Giter Club home page Giter Club logo

class-utils's Introduction

Class::Utils

role Has

Some of the core classes don't run through bless during object creation (apparently for efficiency reasons). This means that if you define a class that inherits from Array, for example, you can't define properties for the class using the normal has route.

The Has role addresses this by importing a new new that takes advantage of bless.

Usage

The following code breaks. If you try to access $.foo below, you get an undefined Any value instead of 'bar'.

class MySet is Array {
  has $.foo = 'bar';
}

say MySet.new.foo;    # Any()

Fix this with does Has from Class::Utils:

use Class::Utils;

class MySet is Array does Has {
  has $.foo = 'bar';
}

say MySet.new.foo;    # bar

class-utils's People

Contributors

sirrobert avatar zoffixznet avatar samcv avatar

Stargazers

Tom Browder avatar Michal Jurosz avatar

Watchers

 avatar James Cloos avatar

class-utils's Issues

new method's signature was changed(or so it seems)

โžœ  ~ perl6 --version
This is Rakudo version 2017.04.2-15-g736be4d built on MoarVM version 2017.04
implementing Perl 6.c.

and then

zef install Class::Utils

and

===> Testing: Class::Utils:ver('0.1.0'):auth('Sir Robert Burbridge')
Too many positionals passed; expected 1 argument but got 2
  in method new at /home/sena/.zef/store/Class-Utils.git/de503e4d2491e9aba2237090d53244fbdfe308d2/lib/Class/Utils.pm6 (Class::Utils) line 9
  in block <unit> at t/01-can-has.t line 16

t/01-can-has.t ..1/2# Looks like you planned 2 tests, but ran 1
t/01-can-has.t .. All 2 subtests passed 
All tests successful.

Test Summary Report
-------------------
t/01-can-has.t (Wstat: 0 Tests: 1 Failed: 0)
  Parse errors: Bad plan.  You planned 2 tests but ran 1.
Files=1, Tests=1,  0 wallclock secs
Result: FAILED
===> Testing [FAIL]: Class::Utils:ver('0.1.0'):auth('Sir Robert Burbridge')
Aborting due to test failure: Class::Utils:ver('0.1.0'):auth('Sir Robert Burbridge') (use --force to override)
  in code  at /home/sena/.rakudobrew/moar-nom/install/share/perl6/site/sources/4B1D5A60B59D9541E13F76E0E2A2D550E0144053 (Zef::Client) line 346
  in method test at /home/sena/.rakudobrew/moar-nom/install/share/perl6/site/sources/4B1D5A60B59D9541E13F76E0E2A2D550E0144053 (Zef::Client) line 325
  in code  at /home/sena/.rakudobrew/moar-nom/install/share/perl6/site/sources/4B1D5A60B59D9541E13F76E0E2A2D550E0144053 (Zef::Client) line 497
  in sub  at /home/sena/.rakudobrew/moar-nom/install/share/perl6/site/sources/4B1D5A60B59D9541E13F76E0E2A2D550E0144053 (Zef::Client) line 494
  in method install at /home/sena/.rakudobrew/moar-nom/install/share/perl6/site/sources/4B1D5A60B59D9541E13F76E0E2A2D550E0144053 (Zef::Client) line 600
  in sub MAIN at /home/sena/.rakudobrew/moar-nom/install/share/perl6/site/sources/09969B10D9F270B8DBAAB9961FA7E6CDB8AD58C9 (Zef::CLI) line 139
  in block <unit> at /home/sena/.rakudobrew/moar-nom/install/share/perl6/site/resources/85BD232410222F167A35B9969B036802FECD78D2 line 1

feature request: utility program to test if a class needs this module.

15:37 < PerlJam> sirrobert: You say "Array for example" ... do you know any other classes that have this problem? A
nice addition to your module might be something that shows which classes require it. Like a program
that you can run to test a particular class maybe?
15:37 < sirrobert> good idea. I don't know of any off the top of my head (I just tried with Array), but I can check
easily enough
15:38 < sirrobert> Can you add that as an issue in the module's repo?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.