XS, which should help us catch skew between the XS/pure Perl
code (Dave Rolsky)
+ * Class::MOP::Class
+ - The alias_method method has been deprecated. It now simply
+ calls add_method instead. This means there is no distinction
+ between aliased methods and "real" methods. (Dave Rolsky)
+
0.65 Mon September 1, 2008
For those not following the series of dev releases, the changes
from 0.64 from 0.65 can mostly be summed up as a lot performance
*check_package_cache_flag = \&mro::get_pkg_gen;
}
-our $VERSION = '0.65';
+our $VERSION = '0.66';
our $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
}
sub alias_method {
- my ($self, $method_name, $method) = @_;
- (defined $method_name && $method_name)
- || confess "You must define a method name";
-
- my $body = (blessed($method) ? $method->body : $method);
- ('CODE' eq ref($body))
- || confess "Your code block must be a CODE reference";
-
- $self->add_package_symbol(
- { sigil => '&', type => 'CODE', name => $method_name } => $body
- );
+ my $self = shift;
- $self->update_package_cache_flag; # the method map will not list aliased methods
+ $self->add_method(@_);
}
sub has_method {
=item B<add_method ($method_name, $method, %attrs)>
-This will take a C<$method_name> and CODE reference to that
-C<$method> and install it into the class's package.
+This will take a C<$method_name> and CODE reference or meta method
+objectand install it into the class's package.
+
+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, providing more useful information about the method
+for introspection.
B<NOTE>:
This does absolutely nothing special to C<$method>
correct name, and therefore show up correctly in stack traces and
such.
-=item B<alias_method ($method_name, $method)>
-
-This will take a C<$method_name> and CODE reference to that
-C<$method> and alias the method into the class's package.
-
-B<NOTE>:
-Unlike C<add_method>, this will B<not> try to name the
-C<$method> using B<Sub::Name>, it only aliases the method in
-the class's package.
-
=item B<has_method ($method_name)>
This just provides a simple way to check if the class implements
the superclasses, this is basically equivalent to calling
C<SUPER::$method_name>, but it can be dispatched at runtime.
+=item B<alias_method ($method_name, $method)>
+
+B<NOTE>: This method is now deprecated. Just use C<add_method>
+instead.
+
=back
=head2 Method Modifiers
sub name { (shift)->{'name'} }
sub fully_qualified_name {
- my $code = shift;
- $code->package_name . '::' . $code->name;
+ my $self = shift;
+ $self->package_name . '::' . $self->name;
}
# NOTE:
$Foo->alias_method('alias_me' => Foo::Aliasing->meta->get_method('alias_me'));
-ok(!$Foo->has_method('alias_me'), '... !Foo->has_method(alias_me) (aliased from Foo::Aliasing)');
+ok($Foo->has_method('alias_me'), '... Foo->has_method(alias_me) (aliased from Foo::Aliasing)');
ok(defined &Foo::alias_me, '... Foo does have a symbol table slow for alias_me though');
ok(!$Foo->has_method('blessed'), '... !Foo->has_method(blessed) (imported into Foo)');
is_deeply(
[ sort $Foo->get_method_list ],
- [ qw(FOO_CONSTANT baaz bang bar baz blah evaled_foo floob foo) ],
+ [ qw(FOO_CONSTANT alias_me baaz bang bar baz blah evaled_foo floob foo) ],
'... got the right method list for Foo');
is_deeply(
[
map { $Foo->get_method($_) } qw(
FOO_CONSTANT
+ alias_me
baaz
bang
bar
is_deeply(
[ sort $Foo->get_method_list ],
- [ qw(FOO_CONSTANT baaz bang bar baz blah evaled_foo floob) ],
+ [ qw(FOO_CONSTANT alias_me baaz bang bar baz blah evaled_foo floob) ],
'... got the right method list for Foo');
[ sort { $a->name cmp $b->name } $Bar->get_all_methods() ],
[
$Foo->get_method('FOO_CONSTANT'),
+ $Foo->get_method('alias_me'),
$Foo->get_method('baaz'),
$Foo->get_method('bang'),
$Bar->get_method('bar'),
ok(! $meta->has_method('zxy') ,'... we dont have the aliased method yet');
ok( $meta->alias_method('zxy',sub{'xxx'}),'... aliased method');
- ok(! $meta->has_method('zxy') ,'... the aliased method does not register (correctly)');
+ ok( $meta->has_method('zxy') ,'... the aliased method does register');
is( Baz->zxy, 'xxx', '... method zxy works');
ok( $meta->remove_method('xyz'), '... removed method');
- ok(! $meta->remove_method('zxy'), '... removed aliased method');
+ ok( $meta->remove_method('zxy'), '... removed aliased method');
ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute');
ok(Baz->can('fickle'), '... Baz can fickle');
ok( $meta->alias_method('zxy',sub{'xxx'}),'... aliased method');
is( $instance->zxy, 'xxx', '... method zxy works');
ok( $meta->remove_method('xyz'), '... removed method');
- ok( !$meta->remove_method('zxy'), '... removed aliased method');
+ ok( $meta->remove_method('zxy'), '... removed aliased method');
ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute');
ok($instance->can('fickle'), '... instance can fickle');