Acme-Has-Tiny

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


        `is => "ro" | "rw" | "rwp"`
            Defaults to "ro".

        `required => 1`
        `default => $coderef`
            Defaults are always eager (not lazy).

        `builder => $coderef | $method_name | 1`
            Builders are always lazy.

        `predicate => $method_name | 1`
        `isa => $type`
            Type constraint (use Types::Standard or another
            Type::Library-based type constraint library).

    `create_constructor $method_name, %options`
        If you want a constructor, then you could call this after defining
        your attributes. (Or you could just import `new` from this module.)

           package Person;
   
           use Acme::Has::Tiny qw(has);
           use Types::Standard -types;
   
           has name => (isa => Str);
           has age  => (isa => Num);
   
           Acme::Has::Tiny->create_constructor("new");
           Acme::Has::Tiny->create_constructor(
              "new_from_arrayref",
              buildargs => sub {
                 my ($class, $aref) = @_;
                 return { name => $aref->[0], age => $aref->[1] };
              },
           );

        Currently supported options:

        `buildargs => $coderef | $method_name`
        `build => $coderef | $method_name`
        `class => $class_name`
            Package to build a constructor for; if omitted, uses the caller.

        `replace => $bool`
            Allow `create_constructor` to overwrite an existing method.

        There's no law that says you have to use `create_constructor`. You can
        write your own constructor if you like. In which case, you might like
        to make use of...

    `assert_valid($class, \%params)`
        Check that a hash of parameters is valid according to type constraints
        and required attributes of $class and any classes it inherits from.

        Returns the hashref or dies.

           sub new {
              my ($class, %params) = @_;
              ...; # other stuff here
              my $self = bless(
                 Acme::Has::Tiny->assert_valid($class, \%params),
                 $class,
              );
              ...; # other stuff here
              return $self;
           }

  Constants
    `CAN_HAZ_XS`
        Whether Class::XSAccessor can be used.

CAVEATS
    Inheriting attributes from parent classes is not super well-tested.

BUGS
    Please report any bugs to
    <http://rt.cpan.org/Dist/Display.html?Queue=Acme-Type-Tiny>.

SEE ALSO
    Moo, Moose, Mouse.

AUTHOR
    Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE
    This software is copyright (c) 2013 by Toby Inkster.

    This is free software; you can redistribute it and/or modify it under the
    same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTIES
    THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
    WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
    MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.



( run in 1.147 second using v1.01-cache-2.11-cpan-5735350b133 )