Aion
view release on metacpan or search on metacpan
lib/Aion/Pleroma.pm view on Meta::CPAN
class: 'Ex::Eon::Astronomer'
arguments: [ 'Galileo Galilei', 'refracting telescope' ]
calls:
- [observe, '@Ex::Eon::Saturn']
Ex::Eon::Jupiter:
class: 'Ex::Eon::Planet'
arguments:
name: 'Jupiter'
moons: 95
discoverer: '@Ex::Eon::Galileo'
Ex::Eon::Saturn:
class: 'Ex::Eon::Planet'
arguments:
name: 'Saturn'
moons: 146
Let's load the configuration from C<etc/aion/eon.yml>, create a container and request eons.
use Aion::Pleroma;
use Aion::Env::Etc ();
my $etc = Aion::Env::Etc::parse('etc/aion/eon.yml');
my $pleroma = Aion::Pleroma->new(pleroma => $etc->{aion}{eon});
my $galileo = $pleroma->resolve('Ex::Eon::Galileo');
$galileo->name # => Galileo Galilei
$galileo->telescope # => refracting telescope
ref($galileo->seen->[0]) # => Ex::Eon::Planet
$galileo->seen->[0]->name # => Saturn
my $jupiter = $pleroma->resolve('Ex::Eon::Jupiter');
$jupiter->name # => Jupiter
$jupiter->moons # => 95
$jupiter->discoverer->name # => Galileo Galilei
ref($jupiter->discoverer) # => Ex::Eon::Astronomer
=head2 Eon description keys
Each eon in C<aion.eon> is described by a string or hash.
The line specifies the constructor C<'class#method'> (or just C<'class'>), the default method is C<new>. This is how the simplest eons are created without arguments.
The hash can contain the keys:
=over
=item * C<class> â class (package) of the eon. If not specified and the eon key is similar to the class name (C</^[\w:]+$/>), the key itself is used.
=item * C<method> â method of the constructor class. Defaults to C<new>.
=item * C<arguments> â constructor arguments:
=item * hash â named arguments (C<< new =E<gt> %hash >>);
=item * array â ordered arguments (C<< new =E<gt> @array >>).
=item * C<calls> â list of method calls after eon creation. Each call is a method name (without arguments) or an array C<[method_name, arguments...]>.
=back
An argument (or call element) value starting with C<@> is treated as a reference to another eon: C<@key> is replaced by the child eon from the container.
=head1 FEATURES
=head2 ini
Annotation file.
Aion::Pleroma->new->ini # => etc/annotation/eon.ann
=head2 pleroma
Configuration: key => 'class#class_method'.
File lib/Ex/Eon/AnimalEon.pm:
package Ex::Eon::AnimalEon;
#@eon
use common::sense;
use Aion;
has role => (is => 'ro');
#@eon ex.cat
sub cat { __PACKAGE__->new(role => 'cat') }
#@eon
sub dog { __PACKAGE__->new(role => 'dog') }
1;
File etc/annotation/eon.ann:
Ex::Eon::AnimalEon#,2=
Ex::Eon::AnimalEon#cat,10=ex.cat
Ex::Eon::AnimalEon#dog,13=Ex::Eon::AnimalEon#dog
Aion::Pleroma->new->pleroma # --> {"Ex::Eon::AnimalEon" => "Ex::Eon::AnimalEon#new", "Ex::Eon::AnimalEon#dog" => "Ex::Eon::AnimalEon#dog", "ex.cat" => "Ex::Eon::AnimalEon#cat", "Aion::Pleroma" => "Aion::Pleroma#new"}
=head2 eon
The totality of generated eons.
my $pleroma = Aion::Pleroma->new;
$pleroma->eon # --> { "Aion::Pleroma" => $pleroma }
my $cat = $pleroma->resolve('ex.cat');
$pleroma->eon # --> { "ex.cat" => $cat, "Aion::Pleroma" => $pleroma }
=head1 SUBROUTINES
=head2 get ($key)
Receive an eon from the container.
my $pleroma = Aion::Pleroma->new;
$pleroma->get('') # -> undef
( run in 1.424 second using v1.01-cache-2.11-cpan-a49fcb8fa48 )