NAME
YAOO - Yet Another Object Orientation
VERSION
Version 0.09
SYNOPSIS
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;
keywords
The following keywords are exported automatically when you declare the use of YAOO.
has
Declare an attribute/accessor.
has one => ro, isa(object);
ro
Set the attribute to read only, so it can only be set on instantiation of the YAOO object.
has two => ro;
rw
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;
isa
Declare a type for the attribute, see the types below for all the current valid options.
has four => isa(any($default_value));
any
Allow any value to be set for the attribute.
has five => isa(any);
string
Allow only string values to be set for the attribute.
has six => isa(string);
scalarref
Allow only scalar references to be set for the attribute.
has seven => isa(scalarref);
integer
Allow only integer values to be be set for the attribute.
has eight => isa(integer(10));
float
Allow only floats to be set for the attribute.
has nine => isa(float(211.11));
boolean
Allow only boolean values to be set for the attribute.
has ten => isa(boolean(\1));
ordered_hash
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 ));
hash
Allow only hash values to be set for the attribute.
has twelve => isa(hash);
array
Allow only array values to be set for the attribute.
has thirteen => isa(array);
object
Allow any object to be set for the attribute.
has fourteen => isa(object);
fh
Allow any file handle to be set for the attribute
has fifthteen => isa(fh);
default
Set the default value for the attribute, this can also be done by passing in the isa type.
has sixteen => isa(string), default('abc');
coerce
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();
});
required
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};
});
trigger
Define a trigger sub which is called after the attribute has been set..
has nineteen => isa(hash) trigger(sub {
$_[0]->no_consent;
});
lazy
Make the attribute lazy so that it is instantiated early.
has twenty => isa(string('Foo::Bar')), lazy;
delay
Make the attribute delayed so that it is instantiated late.
has twenty_one => isa(object), delay, coerce(sub { $_[0]->twenty->new });
build_order
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);
extends
Declare inheritance.
extends 'Moonlight';
requires_has
Decalre attributes that must exist in the inheritance of the object.
require_has qw/one two three/
requires_sub
Declare sub routines/methods that must exist in the inheritance of the object.
require_sub qw/transparency dishonesty/
AUTHOR
LNATION, <email at lnation.org>
BUGS
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.
SUPPORT
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)
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
This software is Copyright (c) 2022 by LNATION.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)