('CODE' eq (Scalar::Util::reftype($code) || ''))
|| confess "You must supply a CODE reference to bless, not (" . ($code || 'undef') . ")";
+ ($options{package_name} && $options{name})
+ || confess "You must supply the package_name and name parameters";
+
# return the new object
$class->meta->new_object(body => $code, %options);
});
Class::MOP::Method::Generated->meta->add_method('new' => sub {
my ($class, %options) = @_;
+ ($options{package_name} && $options{name})
+ || confess "You must supply the package_name and name parameters";
my $self = $class->meta->new_object(%options);
$self->initialize_body;
$self;
(Scalar::Util::blessed($options{attribute}) && $options{attribute}->isa('Class::MOP::Attribute'))
|| confess "You must supply an attribute which is a 'Class::MOP::Attribute' instance";
+ ($options{package_name} && $options{name})
+ || confess "You must supply the package_name and name parameters";
+
# return the new object
my $self = $class->meta->new_object(%options);
|| confess "You must pass a metaclass instance if you want to inline"
if $options{is_inline};
+ ($options{package_name} && $options{name})
+ || confess "You must supply the package_name and name parameters";
+
# return the new object
my $self = $class->meta->new_object(%options);
#warn "Checking $pkg against $class_name && $name against __ANON__";
- $map->{$symbol} = $method_metaclass->wrap($code);
+ $map->{$symbol} = $method_metaclass->wrap(
+ $code,
+ package_name => $class_name,
+ name => $symbol,
+ );
}
return $map;
('CODE' eq (reftype($code) || ''))
|| confess "You must supply a CODE reference to bless, not (" . ($code || 'undef') . ")";
+ ($params{package_name} && $params{name})
+ || confess "You must supply the package_name and name parameters";
+
bless {
'&!body' => $code,
'$!package_name' => $params{package_name},
(blessed($options{attribute}) && $options{attribute}->isa('Class::MOP::Attribute'))
|| confess "You must supply an attribute which is a 'Class::MOP::Attribute' instance";
+ ($options{package_name} && $options{name})
+ || confess "You must supply the package_name and name parameters";
+
my $self = bless {
# from our superclass
'&!body' => undef,
|| confess "You must pass a metaclass instance if you want to inline"
if $options{is_inline};
+ ($options{package_name} && $options{name})
+ || confess "You must supply the package_name and name parameters";
+
my $self = bless {
# from our superclass
'&!body' => undef,
my $class = shift;
my %options = @_;
+ ($options{package_name} && $options{name})
+ || confess "You must supply the package_name and name parameters";
+
my $self = bless {
# from our superclass
'&!body' => undef,
use strict;
use warnings;
-use Test::More tests => 25;
+use Test::More tests => 28;
use Test::Exception;
BEGIN {
use_ok('Class::MOP::Method');
}
-my $method = Class::MOP::Method->wrap(sub { 1 });
+my $method = Class::MOP::Method->wrap(
+ sub { 1 },
+ package_name => 'main',
+ name => '__ANON__',
+);
is($method->meta, Class::MOP::Method->meta, '... instance and class both lead to the same meta');
is($method->package_name, 'main', '... our package is main::');
dies_ok {
Class::MOP::Method->wrap([])
-} '... bad args for &wrap';
\ No newline at end of file
+} '... bad args for &wrap';
+
+dies_ok {
+ Class::MOP::Method->wrap(sub { 'FAIL' })
+} '... bad args for &wrap';
+
+dies_ok {
+ Class::MOP::Method->wrap(sub { 'FAIL' }, package_name => 'main')
+} '... bad args for &wrap';
+
+dies_ok {
+ Class::MOP::Method->wrap(sub { 'FAIL' }, name => '__ANON__')
+} '... bad args for &wrap';
+
+
+
+
+
{
my $trace = '';
- my $method = Class::MOP::Method->wrap(sub { $trace .= 'primary' });
+ my $method = Class::MOP::Method->wrap(
+ sub { $trace .= 'primary' },
+ package_name => 'main',
+ name => '__ANON__',
+ );
isa_ok($method, 'Class::MOP::Method');
$method->();
# test around method
{
- my $method = Class::MOP::Method->wrap(sub { 4 });
+ my $method = Class::MOP::Method->wrap(
+ sub { 4 },
+ package_name => 'main',
+ name => '__ANON__',
+ );
isa_ok($method, 'Class::MOP::Method');
is($method->(), 4, '... got the right value from the wrapped method');
{
my @tracelog;
- my $method = Class::MOP::Method->wrap(sub { push @tracelog => 'primary' });
+ my $method = Class::MOP::Method->wrap(
+ sub { push @tracelog => 'primary' },
+ package_name => 'main',
+ name => '__ANON__',
+ );
isa_ok($method, 'Class::MOP::Method');
my $wrapped = Class::MOP::Method::Wrapped->wrap($method);