YAOO - Yet Another Object Orientation
Version 0.09
package Synopsis; use YAOO; auto_build; has moon => ro, isa(hash(a => "b", c => "d", e => [qw/1 2 3/], f => { 1 => { 2 => { 3 => 4 } } })), lazy, build_order(3); has stars => rw, isa(array(qw/a b c d/)), lazy, build_order(3); has satellites => rw, isa(integer), lazy, build_order(2); has mind => rw, isa(ordered_hash( chang => 1, zante => 2, oistins => 3 )), lazy, build_order(1); has [qw/look up/] => isa(string), delay, coerce(sub { my $followed = [qw/moon starts satellites/]->[int(rand(3))]; $_[0]->$followed; }); has clouds => isa( typed_hash( [ strict => 1, required => [qw/a b c/], keys => [ moon => Int, stars => Str, satellites => typed_hash([keys => [ mind => Str ]], %{$_[0]}) ], ], moon => 211, stars => 'test' satellites => { custom => 'after', mind => 'abc', }, ) ); 1; ... Synopsis->new( satellites => 5 ); $synopsis->mind->{oistins}; ... package Life; extends 'Synopsis'; requires_has qw/moon stars satellites mind/ 1;
The following keywords are exported automatically when you declare the use of YAOO.
Declare an attribute/accessor.
has one => ro, isa(object);
Set the attribute to read only, so it can only be set on instantiation of the YAOO object.
has two => ro;
Set the attribute tp read write, so it can be set at any time. This is the default if you do not provide ro or rw when declaring your attribute.
has three => rw;
Declare a type for the attribute, see the types below for all the current valid options.
has four => isa(any($default_value));
Allow any value to be set for the attribute.
has five => isa(any);
Allow only string values to be set for the attribute.
has six => isa(string);
Allow only scalar references to be set for the attribute.
has seven => isa(scalarref);
Allow only integer values to be be set for the attribute.
has eight => isa(integer(10));
Allow only floats to be set for the attribute.
has nine => isa(float(211.11));
Allow only boolean values to be set for the attribute.
has ten => isa(boolean(\1));
Allow only hash values to be set for the attribute, this will also assist with declaring a ordered hash which has a predicatable order for the keys based upon how it is defined.
has eleven => isa(ordered_hash( one => 1, two => 2, three => 3 ));
Allow only hash values to be set for the attribute.
has twelve => isa(hash);
Allow only array values to be set for the attribute.
has thirteen => isa(array);
Allow any object to be set for the attribute.
has fourteen => isa(object);
Allow any file handle to be set for the attribute
has fifthteen => isa(fh);
Set the default value for the attribute, this can also be done by passing in the isa type.
has sixteen => isa(string), default('abc');
Define a coerce sub routine so that you can manipulate the passed value when ever it is set.
has seventeen => isa(object(1)), coerce(sub { JSON->new(); });
Define a required sub routing so that you can dynamically check for required keys/values for the given attribute.
has eighteen => isa(hash) required(sub { die "the world is a terrible place" if not $_[1]->{honesty}; });
Define a trigger sub which is called after the attribute has been set..
has nineteen => isa(hash) trigger(sub { $_[0]->no_consent; });
Make the attribute lazy so that it is instantiated early.
has twenty => isa(string('Foo::Bar')), lazy;
Make the attribute delayed so that it is instantiated late.
has twenty_one => isa(object), delay, coerce(sub { $_[0]->twenty->new });
Configure a build order for the attributes, this allows you to control the order in which they are 'set'.
has twenty_two => isa(string), build_order(18);
Declare inheritance.
extends 'Moonlight';
Decalre attributes that must exist in the inheritance of the object.
require_has qw/one two three/
Declare sub routines/methods that must exist in the inheritance of the object.
require_sub qw/transparency dishonesty/
LNATION, <email at lnation.org>
<email at lnation.org>
Please report any bugs or feature requests to bug-yaoo at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=YAOO. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-yaoo at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc YAOO
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
https://rt.cpan.org/NoAuth/Bugs.html?Dist=YAOO
CPAN Ratings
https://cpanratings.perl.org/d/YAOO
Search CPAN
https://metacpan.org/release/YAOO
This software is Copyright (c) 2022 by LNATION.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install YAOO, copy and paste the appropriate command in to your terminal.
cpanm
cpanm YAOO
CPAN shell
perl -MCPAN -e shell install YAOO
For more information on module installation, please visit the detailed CPAN module installation guide.