NAME

Mars::Meta - Class Metadata

ABSTRACT

Class Metadata for Perl 5

SYNOPSIS

package Person;

use Mars::Class;

attr 'fname';
attr 'lname';

package Identity;

use Mars::Role;

attr 'id';
attr 'login';
attr 'password';

sub EXPORT {
  # explicitly declare routines to be consumed
  ['id', 'login', 'password']
}

package Authenticable;

use Mars::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 User;

use Mars::Class;

base 'Person';

with 'Identity';

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'}, 'Mars::Meta')

DESCRIPTION

This package provides configuration information for Mars derived classes, roles, and interfaces.

METHODS

This package provides the following methods:

attr

attr(Str $name) (Bool)

The attr method returns true or false if the package referenced has the attribute accessor named.

Since 0.01

attr example 1
# given: synopsis

package main;

my $attr = $meta->attr('email');

# 1
attr example 2
# given: synopsis

package main;

my $attr = $meta->attr('username');

# 0

attrs

attrs() (ArrayRef)

The attrs method returns all of the attributes composed into the package referenced.

Since 0.01

attrs example 1
# given: synopsis

package main;

my $attrs = $meta->attrs;

# [
#   'email',
#   'fname',
#   'id',
#   'lname',
#   'login',
#   'password',
# ]

base

base(Str $name) (Bool)

The base method returns true or false if the package referenced has inherited the package named.

Since 0.01

base example 1
# given: synopsis

package main;

my $base = $meta->base('Person');

# 1
base example 2
# given: synopsis

package main;

my $base = $meta->base('Student');

# 0

bases

bases() (ArrayRef)

The bases method returns returns all of the packages inherited by the package referenced.

Since 0.01

bases example 1
# given: synopsis

package main;

my $bases = $meta->bases;

# [
#   'Person',
#   'Mars::Kind::Class',
#   'Mars::Kind',
# ]

data

data() (HashRef)

The data method returns a data structure representing the shallow configuration for the package referenced.

Since 0.01

data example 1
# given: synopsis

package main;

my $data = $meta->data;

# {
#   'ATTR' => {
#     'email' => [
#       'email'
#     ]
#   },
#   'BASE' => {
#     'Person' => [
#       'Person'
#     ]
#   },
#   'ROLE' => {
#     'Authenticable' => [
#       'Authenticable'
#     ],
#     'Identity' => [
#       'Identity'
#     ]
#   }
# }

new

new(Any %args | HashRef $args) (Object)

The new method returns a new instance of this package.

Since 0.01

new example 1
# given: synopsis

package main;

my $meta = Mars::Meta->new(name => 'User');

# bless({name => 'User'}, 'Mars::Meta')
new example 2
# given: synopsis

package main;

my $meta = Mars::Meta->new({name => 'User'});

# bless({name => 'User'}, 'Mars::Meta')

role

role(Str $name) (Bool)

The role method returns true or false if the package referenced has consumed the role named.

Since 0.01

role example 1
# given: synopsis

package main;

my $role = $meta->role('Identity');

# 1
role example 2
# given: synopsis

package main;

my $role = $meta->role('Builder');

# 0

roles

roles() (ArrayRef)

The roles method returns all of the roles composed into the package referenced.

Since 0.01

roles example 1
# given: synopsis

package main;

my $roles = $meta->roles;

# [
#   'Identity',
#   'Authenticable'
# ]

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.

Since 0.01

sub example 1
# given: synopsis

package main;

my $sub = $meta->sub('authenticate');

# 1
sub example 2
# given: synopsis

package main;

my $sub = $meta->sub('authorize');

# 0

subs

subs() (ArrayRef)

The subs method returns all of the subroutines composed into the package referenced.

Since 0.01

subs example 1
# given: synopsis

package main;

my $subs = $meta->subs;

# [
#   'attr', ...,
#   'base',
#   'email',
#   'false',
#   'fname', ...,
#   'id',
#   'lname',
#   'login',
#   'new', ...,
#   'role',
#   'test',
#   'true',
#   'with', ...,
# ]

AUTHORS

Awncorp, awncorp@cpan.org