Object-Pad
view release on metacpan or search on metacpan
lib/Object/Pad/MOP/Class.pm view on Meta::CPAN
}
=head2 create_class
my $metaclass = Object::Pad::MOP::Class->create_class( $name, %args );
I<Since version 0.61.>
Creates a new class of the given name and yields the metaclass for it.
Takes the following additional named arguments:
=over 4
=item extends => STRING
=item isa => STRING
An optional name of a superclass that this class will extend. These options
are synonyms; new code should use C<isa>, as C<extends> will eventually be
removed.
=item abstract => BOOL
Optionally; if given a true value the newly-created class will be declared as
abstract, as if the L<C<:abstract>|Object::Pad/:abstract> attribute had been
applied.
=back
Once created, this metaclass must be sealed using the L</seal> method before
it can be used to actually construct object instances.
=head2 create_role
my $metaclass = Object::Pad::MOP::Class->create_role( $name, %args );
I<Since version 0.61.>
As L</create_class> but creates a role instead of a class.
=cut
sub create_class { shift->_create_class( shift, @_ ); }
sub create_role { shift->_create_role ( shift, @_ ); }
=head2 begin_class
BEGIN {
my $metaclass = Object::Pad::MOP::Class->begin_class( $name, %args );
...
}
I<Since version 0.46.>
A variant of L</create_class> which sets the newly-created class as the
current complication scope of the surrounding code, allowing it to accept
C<Object::Pad> syntax forms such as C<has> and C<method>.
This must be done during C<BEGIN> time because of this compiletime effect.
It additionally creates a deferred code block at C<UNITCHECK> time of its
surrounding scope, which is used to finalise the constructed class. In this
case you do not need to remember to call L</seal> on it; this happens
automatically.
=head2 begin_role
I<Since version 0.46.>
As L</begin_class> but creates a role instead of a class.
=cut
sub begin_class { shift->_create_class( shift, _set_compclassmeta => 1, @_ ); }
sub begin_role { shift->_create_role ( shift, _set_compclassmeta => 1, @_ ); }
=head1 METHODS
=head2 is_class
=head2 is_role
$bool = $metaclass->is_class;
$bool = $metaclass->is_role;
Exactly one of these methods will return true, depending on whether this
metaclass instance represents a true C<class>, or a C<role>.
=head2 is_abstract
$bool = $metaclass->is_abstract;
True on a C<role>, or a C<class> that was declared with the C<:abstract>
attribute.
=head2 name
$name = $metaclass->name;
Returns the name of the class, as a plain string.
=head2 superclasses
@classes = $metaclass->superclasses;
Returns a list of superclasses, as L<Object::Pad::MOP::Class> instances.
Because C<Object::Pad> does not support multiple superclasses, this list will
contain at most one item.
=head2 direct_roles
@roles = $metaclass->direct_roles;
Returns a list of the roles introduced by this class (i.e. added by `does`
declarations but not inherited from the superclass), as
L<Object::Pad::MOP::Class> instances.
This method is also aliased as C<roles>.
=head2 all_roles
( run in 2.091 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )