Venus::Meta - Class Metadata
Class Metadata for Perl 5
package Person; use Venus::Class; attr 'fname'; attr 'lname'; package Identity; use Venus::Role; attr 'id'; attr 'login'; attr 'password'; sub EXPORT { # explicitly declare routines to be consumed ['id', 'login', 'password'] } package Authenticable; use Venus::Role; sub authenticate { return true; } sub AUDIT { my ($self, $from) = @_; # ensure the caller has a login and password when consumed die "${from} missing the login attribute" if !$from->can('login'); die "${from} missing the password attribute" if !$from->can('password'); } sub EXPORT { # explicitly declare routines to be consumed ['authenticate'] } package Novice; use Venus::Mixin; sub points { 100 } package User; use Venus::Class 'attr', 'base', 'mixin', 'test', 'with'; base 'Person'; with 'Identity'; mixin 'Novice'; attr 'email'; test 'Authenticable'; sub valid { my ($self) = @_; return $self->login && $self->password ? true : false; } package main; my $user = User->new( fname => 'Elliot', lname => 'Alderson', ); my $meta = $user->meta; # bless({name => 'User'}, 'Venus::Meta')
This package provides configuration information for Venus derived classes, roles, and interfaces.
This package provides the following methods:
attr(Str $name) (Bool)
The attr method returns true or false if the package referenced has the attribute accessor named.
Since 1.00
1.00
# given: synopsis package main; my $attr = $meta->attr('email'); # 1
# given: synopsis package main; my $attr = $meta->attr('username'); # 0
attrs() (ArrayRef)
The attrs method returns all of the attributes composed into the package referenced.
# given: synopsis package main; my $attrs = $meta->attrs; # [ # 'email', # 'fname', # 'id', # 'lname', # 'login', # 'password', # ]
base(Str $name) (Bool)
The base method returns true or false if the package referenced has inherited the package named.
# given: synopsis package main; my $base = $meta->base('Person'); # 1
# given: synopsis package main; my $base = $meta->base('Student'); # 0
bases() (ArrayRef)
The bases method returns returns all of the packages inherited by the package referenced.
# given: synopsis package main; my $bases = $meta->bases; # [ # 'Person', # 'Venus::Core::Class', # 'Venus::Core', # ]
data() (HashRef)
The data method returns a data structure representing the shallow configuration for the package referenced.
# given: synopsis package main; my $data = $meta->data; # { # 'ATTR' => { # 'email' => [ # 'email' # ] # }, # 'BASE' => { # 'Person' => [ # 'Person' # ] # }, # 'ROLE' => { # 'Authenticable' => [ # 'Authenticable' # ], # 'Identity' => [ # 'Identity' # ] # } # }
find(Str $type, Str $name) (Tuple[Str,Tuple[Int,ArrayRef]])
The find method finds and returns the first configuration for the property type specified. This method uses the "search" method to search roles, bases, mixins, and the source package, in the order listed. The "property type" can be any one of attr, base, mixin, or role.
roles
bases
mixins
attr
base
mixin
role
Since 1.02
1.02
# given: synopsis package main; my $find = $meta->find; # ()
# given: synopsis package main; my $find = $meta->find('attr', 'id'); # ['Identity', [ 1, ['id']]]
# given: synopsis package main; my $find = $meta->find('sub', 'valid'); # ['User', [1, [sub {...}]]]
# given: synopsis package main; my $find = $meta->find('sub', 'authenticate'); # ['Authenticable', [1, [sub {...}]]]
local(Str $type) (ArrayRef)
The local method returns the names of properties defined in the package directly (not inherited) for the property type specified. The $type provided can be either attrs, bases, roles, or subs.
$type
attrs
subs
# given: synopsis package main; my $attrs = $meta->local('attrs'); # ['email']
# given: synopsis package main; my $bases = $meta->local('bases'); # ['Person', 'Venus::Core::Class']
# given: synopsis package main; my $roles = $meta->local('roles'); # ['Identity', 'Authenticable']
# given: synopsis package main; my $subs = $meta->local('subs'); # [ # 'attr', # 'authenticate', # 'base', # 'email', # 'false', # 'id', # 'login', # 'password', # 'test', # 'true', # 'valid', # 'with', # ]
mixin(Str $name) (Bool)
The mixin method returns true or false if the package referenced has consumed the mixin named.
# given: synopsis package main; my $mixin = $meta->mixin('Novice'); # 1
# given: synopsis package main; my $mixin = $meta->mixin('Intermediate'); # 0
mixins() (ArrayRef)
The mixins method returns all of the mixins composed into the package referenced.
# given: synopsis package main; my $mixins = $meta->mixins; # [ # 'Novice', # ]
new(Any %args | HashRef $args) (Object)
The new method returns a new instance of this package.
# given: synopsis package main; $meta = Venus::Meta->new(name => 'User'); # bless({name => 'User'}, 'Venus::Meta')
# given: synopsis package main; $meta = Venus::Meta->new({name => 'User'}); # bless({name => 'User'}, 'Venus::Meta')
role(Str $name) (Bool)
The role method returns true or false if the package referenced has consumed the role named.
# given: synopsis package main; my $role = $meta->role('Identity'); # 1
# given: synopsis package main; my $role = $meta->role('Builder'); # 0
roles() (ArrayRef)
The roles method returns all of the roles composed into the package referenced.
# given: synopsis package main; my $roles = $meta->roles; # [ # 'Identity', # 'Authenticable' # ]
search(Str $from, Str $type, Str $name) (ArrayRef[Tuple[Str,Tuple[Int,ArrayRef]]])
The search method searches the source specified and returns the configurations for the property type specified. The source can be any one of bases, roles, mixins, or self for the source package. The "property type" can be any one of attr, base, mixin, or role.
self
# given: synopsis package main; my $search = $meta->search; # ()
# given: synopsis package main; my $search = $meta->search('roles', 'attr', 'id'); # [['Identity', [ 1, ['id']]]]
# given: synopsis package main; my $search = $meta->search('self', 'sub', 'valid'); # [['User', [1, [sub {...}]]]]
# given: synopsis package main; my $search = $meta->search('self', 'sub', 'authenticate'); # [['User', [1, [sub {...}]]]]
sub(Str $name) (Bool)
The sub method returns true or false if the package referenced has the subroutine named on the package directly, or any of its superclasses.
# given: synopsis package main; my $sub = $meta->sub('authenticate'); # 1
# given: synopsis package main; my $sub = $meta->sub('authorize'); # 0
subs() (ArrayRef)
The subs method returns all of the subroutines composed into the package referenced.
# given: synopsis package main; my $subs = $meta->subs; # [ # 'attr', ..., # 'base', # 'email', # 'false', # 'fname', ..., # 'id', # 'lname', # 'login', # 'new', ..., # 'role', # 'test', # 'true', # 'with', ..., # ]
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.