From: Jesse Luehrs Date: Tue, 11 May 2010 02:13:19 +0000 (-0500) Subject: move methods back into CMOP::Class, now that they're a separate mixin X-Git-Tag: 1.02~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f197afa62adde6f15130d570566f752ee7df5f0b;p=gitmo%2FClass-MOP.git move methods back into CMOP::Class, now that they're a separate mixin --- diff --git a/Changes b/Changes index a13c88b..41e39c0 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Revision history for Perl extension Class-MOP. + [API CHANGES] + + * Packages and modules no longer have methods - this functionality was + moved back up into Class::MOP::Class (doy). + 1.01 Thu, May 26, 2010 [NEW FEATURES] diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 801e5d7..cbbc26d 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -19,7 +19,9 @@ our $VERSION = '1.01'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Class::MOP::Module', 'Class::MOP::Mixin::HasAttributes'; +use base 'Class::MOP::Module', + 'Class::MOP::Mixin::HasAttributes', + 'Class::MOP::Mixin::HasMethods'; # Creation @@ -1384,14 +1386,76 @@ include indirect subclasses. =back -=head2 Method introspection +=head2 Method introspection and creation -See L for -methods that operate only on the current class. Class::MOP::Class adds -introspection capabilities that take inheritance into account. +These methods allow you to introspect a class's methods, as well as +add, remove, or change methods. + +Determining what is truly a method in a Perl 5 class requires some +heuristics (aka guessing). + +Methods defined outside the package with a fully qualified name (C) will be included. Similarly, methods named +with a fully qualified name using L are also included. + +However, we attempt to ignore imported functions. + +Ultimately, we are using heuristics to determine what truly is a +method in a class, and these heuristics may get the wrong answer in +some edge cases. However, for most "normal" cases the heuristics work +correctly. =over 4 +=item B<< $metaclass->get_method($method_name) >> + +This will return a L for the specified +C<$method_name>. If the class does not have the specified method, it +returns C + +=item B<< $metaclass->has_method($method_name) >> + +Returns a boolean indicating whether or not the class defines the +named method. It does not include methods inherited from parent +classes. + +=item B<< $metaclass->get_method_list >> + +This will return a list of method I for all methods defined in +this class. + +=item B<< $metaclass->add_method($method_name, $method) >> + +This method takes a method name and a subroutine reference, and adds +the method to the class. + +The subroutine reference can be a L, and you are +strongly encouraged to pass a meta method object instead of a code +reference. If you do so, that object gets stored as part of the +class's method map directly. If not, the meta information will have to +be recreated later, and may be incorrect. + +If you provide a method object, this method will clone that object if +the object's package name does not match the class name. This lets us +track the original source of any methods added from other classes +(notably Moose roles). + +=item B<< $metaclass->remove_method($method_name) >> + +Remove the named method from the class. This method returns the +L object for the method. + +=item B<< $metaclass->method_metaclass >> + +Returns the class name of the method metaclass, see +L for more information on the method metaclass. + +=item B<< $metaclass->wrapped_method_metaclass >> + +Returns the class name of the wrapped method metaclass, see +L for more information on the wrapped +method metaclass. + =item B<< $metaclass->get_all_methods >> This will traverse the inheritance hierarchy and return a list of all diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index 544c71a..6f722b9 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -11,7 +11,7 @@ our $VERSION = '1.01'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Class::MOP::Object', 'Class::MOP::Mixin::HasMethods'; +use base 'Class::MOP::Object'; # creation ... @@ -374,78 +374,6 @@ This works much like C, but it returns a hash reference. The keys are glob names and the values are references to the value for that name. -=back - -=head2 Method introspection and creation - -These methods allow you to introspect a class's methods, as well as -add, remove, or change methods. - -Determining what is truly a method in a Perl 5 class requires some -heuristics (aka guessing). - -Methods defined outside the package with a fully qualified name (C) will be included. Similarly, methods named -with a fully qualified name using L are also included. - -However, we attempt to ignore imported functions. - -Ultimately, we are using heuristics to determine what truly is a -method in a class, and these heuristics may get the wrong answer in -some edge cases. However, for most "normal" cases the heuristics work -correctly. - -=over 4 - -=item B<< $metapackage->get_method($method_name) >> - -This will return a L for the specified -C<$method_name>. If the class does not have the specified method, it -returns C - -=item B<< $metapackage->has_method($method_name) >> - -Returns a boolean indicating whether or not the class defines the -named method. It does not include methods inherited from parent -classes. - -=item B<< $metapackage->get_method_list >> - -This will return a list of method I for all methods defined in -this class. - -=item B<< $metapackage->add_method($method_name, $method) >> - -This method takes a method name and a subroutine reference, and adds -the method to the class. - -The subroutine reference can be a L, and you are -strongly encouraged to pass a meta method object instead of a code -reference. If you do so, that object gets stored as part of the -class's method map directly. If not, the meta information will have to -be recreated later, and may be incorrect. - -If you provide a method object, this method will clone that object if -the object's package name does not match the class name. This lets us -track the original source of any methods added from other classes -(notably Moose roles). - -=item B<< $metapackage->remove_method($method_name) >> - -Remove the named method from the class. This method returns the -L object for the method. - -=item B<< $metapackage->method_metaclass >> - -Returns the class name of the method metaclass, see -L for more information on the method metaclass. - -=item B<< $metapackage->wrapped_method_metaclass >> - -Returns the class name of the wrapped method metaclass, see -L for more information on the wrapped -method metaclass. - =item B<< Class::MOP::Package->meta >> This will return a L instance for this class. diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index c81cb01..00188fb 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -239,36 +239,36 @@ is(ref($class_mop_package_meta->get_attribute('package')->reader), 'HASH', '... ok($class_mop_package_meta->get_attribute('package')->has_init_arg, '... Class::MOP::Class package has a init_arg'); is($class_mop_package_meta->get_attribute('package')->init_arg, 'package', '... Class::MOP::Class package\'s a init_arg is package'); -# ... package, but inherited from HasMethods -ok($class_mop_package_meta->find_attribute_by_name('method_metaclass')->has_reader, '... Class::MOP::Package method_metaclass has a reader'); -is_deeply($class_mop_package_meta->find_attribute_by_name('method_metaclass')->reader, +# ... class, but inherited from HasMethods +ok($class_mop_class_meta->find_attribute_by_name('method_metaclass')->has_reader, '... Class::MOP::Class method_metaclass has a reader'); +is_deeply($class_mop_class_meta->find_attribute_by_name('method_metaclass')->reader, { 'method_metaclass' => \&Class::MOP::Mixin::HasMethods::method_metaclass }, - '... Class::MOP::Package method_metaclass\'s a reader is &method_metaclass'); + '... Class::MOP::Class method_metaclass\'s a reader is &method_metaclass'); -ok($class_mop_package_meta->find_attribute_by_name('method_metaclass')->has_init_arg, '... Class::MOP::Package method_metaclass has a init_arg'); -is($class_mop_package_meta->find_attribute_by_name('method_metaclass')->init_arg, +ok($class_mop_class_meta->find_attribute_by_name('method_metaclass')->has_init_arg, '... Class::MOP::Class method_metaclass has a init_arg'); +is($class_mop_class_meta->find_attribute_by_name('method_metaclass')->init_arg, 'method_metaclass', - '... Class::MOP::Package method_metaclass\'s init_arg is method_metaclass'); + '... Class::MOP::Class method_metaclass\'s init_arg is method_metaclass'); -ok($class_mop_package_meta->find_attribute_by_name('method_metaclass')->has_default, '... Class::MOP::Package method_metaclass has a default'); -is($class_mop_package_meta->find_attribute_by_name('method_metaclass')->default, +ok($class_mop_class_meta->find_attribute_by_name('method_metaclass')->has_default, '... Class::MOP::Class method_metaclass has a default'); +is($class_mop_class_meta->find_attribute_by_name('method_metaclass')->default, 'Class::MOP::Method', - '... Class::MOP::Package method_metaclass\'s a default is Class::MOP:::Method'); + '... Class::MOP::Class method_metaclass\'s a default is Class::MOP:::Method'); -ok($class_mop_package_meta->find_attribute_by_name('wrapped_method_metaclass')->has_reader, '... Class::MOP::Package wrapped_method_metaclass has a reader'); -is_deeply($class_mop_package_meta->find_attribute_by_name('wrapped_method_metaclass')->reader, +ok($class_mop_class_meta->find_attribute_by_name('wrapped_method_metaclass')->has_reader, '... Class::MOP::Class wrapped_method_metaclass has a reader'); +is_deeply($class_mop_class_meta->find_attribute_by_name('wrapped_method_metaclass')->reader, { 'wrapped_method_metaclass' => \&Class::MOP::Mixin::HasMethods::wrapped_method_metaclass }, - '... Class::MOP::Package wrapped_method_metaclass\'s a reader is &wrapped_method_metaclass'); + '... Class::MOP::Class wrapped_method_metaclass\'s a reader is &wrapped_method_metaclass'); -ok($class_mop_package_meta->find_attribute_by_name('wrapped_method_metaclass')->has_init_arg, '... Class::MOP::Package wrapped_method_metaclass has a init_arg'); -is($class_mop_package_meta->find_attribute_by_name('wrapped_method_metaclass')->init_arg, +ok($class_mop_class_meta->find_attribute_by_name('wrapped_method_metaclass')->has_init_arg, '... Class::MOP::Class wrapped_method_metaclass has a init_arg'); +is($class_mop_class_meta->find_attribute_by_name('wrapped_method_metaclass')->init_arg, 'wrapped_method_metaclass', - '... Class::MOP::Package wrapped_method_metaclass\'s init_arg is wrapped_method_metaclass'); + '... Class::MOP::Class wrapped_method_metaclass\'s init_arg is wrapped_method_metaclass'); -ok($class_mop_package_meta->find_attribute_by_name('method_metaclass')->has_default, '... Class::MOP::Package method_metaclass has a default'); -is($class_mop_package_meta->find_attribute_by_name('method_metaclass')->default, +ok($class_mop_class_meta->find_attribute_by_name('method_metaclass')->has_default, '... Class::MOP::Class method_metaclass has a default'); +is($class_mop_class_meta->find_attribute_by_name('method_metaclass')->default, 'Class::MOP::Method', - '... Class::MOP::Package method_metaclass\'s a default is Class::MOP:::Method'); + '... Class::MOP::Class method_metaclass\'s a default is Class::MOP:::Method'); # ... class, but inherited from HasAttributes @@ -315,7 +315,7 @@ is(${$class_mop_class_meta->get_package_symbol('$VERSION')}, is_deeply( [ $class_mop_class_meta->superclasses ], - [ qw/Class::MOP::Module Class::MOP::Mixin::HasAttributes/ ], + [ qw/Class::MOP::Module Class::MOP::Mixin::HasAttributes Class::MOP::Mixin::HasMethods/ ], '... Class::MOP::Class->superclasses == [ Class::MOP::Module ]'); is_deeply( @@ -325,10 +325,10 @@ is_deeply( Class::MOP::Module Class::MOP::Package Class::MOP::Object - Class::MOP::Mixin::HasMethods - Class::MOP::Mixin Class::MOP::Mixin::HasAttributes Class::MOP::Mixin + Class::MOP::Mixin::HasMethods + Class::MOP::Mixin / ], '... Class::MOP::Class->class_precedence_list == [ Class::MOP::Class Class::MOP::Module Class::MOP::Package ]');