=item B<get_all_metaclasses>
+This will return an hash of all the metaclass instances that have
+been cached by B<Class::MOP::Class> keyed by the package name.
+
=item B<get_all_metaclass_instances>
+This will return an array of all the metaclass instances that have
+been cached by B<Class::MOP::Class>.
+
=item B<get_all_metaclass_names>
+This will return an array of all the metaclass names that have
+been cached by B<Class::MOP::Class>.
+
=item B<get_metaclass_by_name ($name)>
=item B<store_metaclass_by_name ($name, $meta)>
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
- Class/MOP.pm 100.0 100.0 100.0 100.0 n/a 19.8 100.0
- Class/MOP/Attribute.pm 100.0 100.0 91.7 61.2 100.0 14.3 87.9
- Class/MOP/Class.pm 97.6 91.3 77.3 98.4 100.0 56.4 93.2
- Class/MOP/Instance.pm 91.1 75.0 33.3 91.7 100.0 6.8 90.7
- Class/MOP/Method.pm 97.6 60.0 52.9 76.9 100.0 1.6 82.6
- metaclass.pm 100.0 100.0 83.3 100.0 n/a 1.0 97.7
+ Class/MOP.pm 78.0 87.5 55.6 71.4 100.0 12.4 76.8
+ Class/MOP/Attribute.pm 83.4 75.6 86.7 94.4 100.0 8.9 85.2
+ Class/MOP/Class.pm 96.9 75.8 43.2 98.0 100.0 55.3 83.6
+ Class/MOP/Class/Immutable.pm 88.5 53.8 n/a 95.8 100.0 1.1 84.7
+ Class/MOP/Instance.pm 87.9 75.0 33.3 89.7 100.0 10.1 89.1
+ Class/MOP/Method.pm 97.6 60.0 57.9 76.9 100.0 1.5 82.8
+ Class/MOP/Module.pm 87.5 n/a 11.1 83.3 100.0 0.3 66.7
+ Class/MOP/Object.pm 100.0 n/a 33.3 100.0 100.0 0.1 89.5
+ Class/MOP/Package.pm 95.1 69.0 33.3 100.0 100.0 9.9 85.5
+ metaclass.pm 100.0 100.0 83.3 100.0 n/a 0.5 97.7
---------------------------- ------ ------ ------ ------ ------ ------ ------
- Total 97.5 88.5 75.5 82.8 100.0 100.0 91.2
+ Total 91.5 72.1 48.8 90.7 100.0 100.0 84.2
---------------------------- ------ ------ ------ ------ ------ ------ ------
=head1 ACKNOWLEDGEMENTS
=over 4
-=item Rob Kinyon E<lt>rob@iinteractive.comE<gt>
+=item Rob Kinyon
Thanks to Rob for actually getting the development of this module kick-started.
sub meta { Class::MOP::Class->initialize(blessed($_[0]) || $_[0]) }
-# Class globals ...
-
-# NOTE:
-# we need a sufficiently annoying prefix
-# this should suffice for now, this is
-# used in a couple of places below, so
-# need to put it up here for now.
-my $ANON_CLASS_PREFIX = 'Class::MOP::Class::__ANON__::SERIAL::';
-
# Creation
sub initialize {
$meta->check_metaclass_compatability();
Class::MOP::store_metaclass_by_name($package_name, $meta);
+
# NOTE:
# we need to weaken any anon classes
# so that they can call DESTROY properly
- Class::MOP::weaken_metaclass($package_name)
- if $package_name =~ /^$ANON_CLASS_PREFIX/;
+ Class::MOP::weaken_metaclass($package_name) if $meta->is_anon_class;
+
$meta;
}
# use case where it is not, write a test and
# I will change it.
my $ANON_CLASS_SERIAL = 0;
+
+ # NOTE:
+ # we need a sufficiently annoying prefix
+ # this should suffice for now, this is
+ # used in a couple of places below, so
+ # need to put it up here for now.
+ my $ANON_CLASS_PREFIX = 'Class::MOP::Class::__ANON__::SERIAL::';
+
+ sub is_anon_class {
+ my $self = shift;
+ $self->name =~ /^$ANON_CLASS_PREFIX/ ? 1 : 0;
+ }
sub create_anon_class {
my ($class, %options) = @_;
my $package_name = $ANON_CLASS_PREFIX . ++$ANON_CLASS_SERIAL;
return $class->create($package_name, '0.00', %options);
- }
-}
+ }
-# NOTE:
-# this will only get called for
-# anon-classes, all other calls
-# are assumed to occur during
-# global destruction and so don't
-# really need to be handled explicitly
-sub DESTROY {
- my $self = shift;
- return unless $self->name =~ /^$ANON_CLASS_PREFIX/;
- my ($serial_id) = ($self->name =~ /^$ANON_CLASS_PREFIX(\d+)/);
- no strict 'refs';
- foreach my $key (keys %{$ANON_CLASS_PREFIX . $serial_id}) {
- delete ${$ANON_CLASS_PREFIX . $serial_id}{$key};
+ # NOTE:
+ # this will only get called for
+ # anon-classes, all other calls
+ # are assumed to occur during
+ # global destruction and so don't
+ # really need to be handled explicitly
+ sub DESTROY {
+ my $self = shift;
+ return unless $self->name =~ /^$ANON_CLASS_PREFIX/;
+ my ($serial_id) = ($self->name =~ /^$ANON_CLASS_PREFIX(\d+)/);
+ no strict 'refs';
+ foreach my $key (keys %{$ANON_CLASS_PREFIX . $serial_id}) {
+ delete ${$ANON_CLASS_PREFIX . $serial_id}{$key};
+ }
+ delete ${'main::' . $ANON_CLASS_PREFIX}{$serial_id . '::'};
}
- delete ${'main::' . $ANON_CLASS_PREFIX}{$serial_id . '::'};
+
}
# creating classes with MOP ...
into it's metaclass. This will allow this class to reap all the benifits
of the MOP when subclassing it.
-=item B<get_all_metaclasses>
-
-This will return an hash of all the metaclass instances that have
-been cached by B<Class::MOP::Class> keyed by the package name.
-
-=item B<get_all_metaclass_instances>
-
-This will return an array of all the metaclass instances that have
-been cached by B<Class::MOP::Class>.
-
-=item B<get_all_metaclass_names>
-
-This will return an array of all the metaclass names that have
-been cached by B<Class::MOP::Class>.
-
=back
=head2 Class construction
=head2 Informational
-=over 4
+These are a few predicate methods for asking information about the class.
-=item B<name>
+=over 4
-This is a read-only attribute which returns the package name for the
-given B<Class::MOP::Class> instance.
+=item B<is_anon_class>
-=item B<version>
+=item B<is_mutable>
-This is a read-only attribute which returns the C<$VERSION> of the
-package for the given B<Class::MOP::Class> instance.
+=item B<is_immutable>
=back
=back
-=head2 Package Variables
-
-Since Perl's classes are built atop the Perl package system, it is
-fairly common to use package scoped variables for things like static
-class variables. The following methods are convience methods for
-the creation and inspection of package scoped variables.
-
-=over 4
-
-=item B<add_package_symbol ($variable_name, ?$initial_value)>
-
-Given a C<$variable_name>, which must contain a leading sigil, this
-method will create that variable within the package which houses the
-class. It also takes an optional C<$initial_value>, which must be a
-reference of the same type as the sigil of the C<$variable_name>
-implies.
-
-=item B<get_package_symbol ($variable_name)>
-
-This will return a reference to the package variable in
-C<$variable_name>.
-
-=item B<has_package_symbol ($variable_name)>
-
-Returns true (C<1>) if there is a package variable defined for
-C<$variable_name>, and false (C<0>) otherwise.
-
-=item B<remove_package_symbol ($variable_name)>
-
-This will attempt to remove the package variable at C<$variable_name>.
-
-=back
-
=head2 Class closing
=over 4
-=item B<is_mutable>
-
-=item B<is_immutable>
-
=item B<make_immutable>
=back
=item B<meta>
-=item B<initialize>
+=item B<initialize ($package_name)>
=item B<name>
+This is a read-only attribute which returns the package name for the
+given instance.
+
=item B<namespace>
-=item B<add_package_symbol>
+This returns a HASH reference to the symbol table. The keys of the
+HASH are the symbol names, and the values are typeglob references.
+
+=item B<add_package_symbol ($variable_name, ?$initial_value)>
+
+Given a C<$variable_name>, which must contain a leading sigil, this
+method will create that variable within the package which houses the
+class. It also takes an optional C<$initial_value>, which must be a
+reference of the same type as the sigil of the C<$variable_name>
+implies.
+
+=item B<get_package_symbol ($variable_name)>
-=item B<get_package_symbol>
+This will return a reference to the package variable in
+C<$variable_name>.
-=item B<has_package_symbol>
+=item B<has_package_symbol ($variable_name)>
-=item B<remove_package_symbol>
+Returns true (C<1>) if there is a package variable defined for
+C<$variable_name>, and false (C<0>) otherwise.
-=item B<remove_package_glob>
+=item B<remove_package_symbol ($variable_name)>
+
+This will attempt to remove the package variable at C<$variable_name>.
+
+=item B<remove_package_glob ($glob_name)>
+
+This will attempt to remove the entire typeglob associated with
+C<$glob_name> from the package.
=item B<list_all_package_symbols>
+This will list all the glob names associated with the current package.
+By inspecting the globs returned you can discern all the variables in
+the package.
+
=back
=head1 AUTHORS