SV *key_package;
U32 hash_package;
+SV *key_package_name;
+U32 hash_package_name;
+
SV *key_body;
U32 hash_body;
key_name = newSVpvs("name");
key_body = newSVpvs("body");
key_package = newSVpvs("package");
+ key_package_name = newSVpvs("package_name");
PERL_HASH(hash_name, "name", 4);
PERL_HASH(hash_body, "body", 4);
PERL_HASH(hash_package, "package", 7);
+ PERL_HASH(hash_package_name, "package_name", 12);
PROTOTYPES: ENABLE
MODULE = Class::MOP PACKAGE = Class::MOP::Method
SV *
+name(self)
+ SV *self
+ PREINIT:
+ register HE *he;
+ PPCODE:
+ if (! SvROK(self)) {
+ die("Cannot call name as a class method");
+ }
+
+ if (he = hv_fetch_ent((HV *)SvRV(self), key_name, 0, hash_name))
+ XPUSHs(HeVAL(he));
+ else
+ ST(0) = &PL_sv_undef;
+
+SV *
+package_name(self)
+ SV *self
+ PREINIT:
+ register HE *he;
+ PPCODE:
+ if (! SvROK(self)) {
+ die("Cannot call package_name as a class method");
+ }
+
+ if (he = hv_fetch_ent((HV *)SvRV(self), key_package_name, 0, hash_package_name))
+ XPUSHs(HeVAL(he));
+ else
+ ST(0) = &PL_sv_undef;
+
+SV *
body(self)
SV *self
PREINIT:
register HE *he;
PPCODE:
- if (SvROK(self) && (he = hv_fetch_ent((HV *)SvRV(self), key_body, 0, hash_body)))
+ if (! SvROK(self)) {
+ die("Cannot call body as a class method");
+ }
+
+ if (he = hv_fetch_ent((HV *)SvRV(self), key_body, 0, hash_body))
XPUSHs(HeVAL(he));
else
ST(0) = &PL_sv_undef;
delete $self->{associated_metaclass};
}
-sub package_name {
- my $self = shift;
- $self->{'package_name'} ||= (Class::MOP::get_code_info($self->body))[0];
-}
+sub package_name { (shift)->{'package_name'} }
-sub name {
- my $self = shift;
- $self->{'name'} ||= (Class::MOP::get_code_info($self->body))[1];
-}
+sub name { (shift)->{'name'} }
sub fully_qualified_name {
my $code = shift;
use strict;
use warnings;
-use Test::More tests => 28;
+use Test::More tests => 27;
use Test::Exception;
-BEGIN {
- use_ok('Class::MOP');
- use_ok('Class::MOP::Method');
-}
+use Class::MOP;
+use Class::MOP::Method;
+
my $method = Class::MOP::Method->wrap(
sub { 1 },
dies_ok { Class::MOP::Method->wrap([]) } q{... can't call wrap() without some code};
dies_ok { Class::MOP::Method->wrap(bless {} => 'Fail') } q{... can't call wrap() without some code};
-dies_ok { Class::MOP::Method->name } q{... can't call name() with a class};
-dies_ok { Class::MOP::Method->package_name } q{... can't call package_name() with a class};
-dies_ok { Class::MOP::Method->fully_qualified_name } q{... can't call fully_qualified_name() with a class};
+dies_ok { Class::MOP::Method->name } q{... can't call name() as a class method};
+dies_ok { Class::MOP::Method->body } q{... can't call body() as a class method};
+dies_ok { Class::MOP::Method->package_name } q{... can't call package_name() as a class method};
+dies_ok { Class::MOP::Method->fully_qualified_name } q{... can't call fully_qualified_name() as a class method};
my $meta = Class::MOP::Method->meta;
isa_ok($meta, 'Class::MOP::Class');