| 1 | package Class::MOP::Method::Constructor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 459 | our $VERSION = '2.4001'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 459 | ▶ | use strict; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 459 | ▶ | use warnings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 459 | ▶ | use Scalar::Util 'blessed', 'weaken'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 459 | ▶ | use Try::Tiny; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 459 | ▶ | use parent 'Class::MOP::Method::Inlined'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11725 | ▶ | sub new { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.2
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 11725 | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 11725 | my %options = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | (blessed $options{metaclass} && $options{metaclass}->isa('Class::MOP::Class')) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | || $class->_throw_exception( MustSupplyAMetaclass => params => \%options, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | class => $class | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 11725 | ▶ | if $options{is_inline}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$options{'is_inline'} && (builtin::blessed($options{'metaclass'}) && $options{'metaclass'}->isa('Class::MOP::Class') || $class->_throw_exception('MustSupplyAMetaclass', 'params', \%options, 'class', $class))
builtin::blessed($options{"metaclass"}) and $options{"metaclass"}->isa("Class::MOP::Class") or $class->_throw_exception("MustSupplyAMetaclass", "params", \%options, "class", $class)
builtin::blessed($options{"metaclass"}) and $options{"metaclass"}->isa("Class::MOP::Class")
MC/DC0%0/4
$options{'is_inline'} && (builtin::blessed($options{'metaclass'}) && $options{'metaclass'}->isa('Class::MOP::Class') || $class->_throw_exception('MustSupplyAMetaclass', 'params', \%options, 'class', $class))
$options{'is_inline'}
builtin::blessed($options{"metaclass"})
$options{"metaclass"}->isa("Class::MOP::Class")
$class->_throw_exception("MustSupplyAMetaclass", "params", \%options, "class", $class)
Truth table0%0/6
A && B and C or D
A= $options{'is_inline'}B= builtin::blessed($options{"metaclass"})C= $options{"metaclass"}->isa("Class::MOP::Class")D= $class->_throw_exception("MustSupplyAMetaclass", "params", \%options, "class", $class)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ($options{package_name} && $options{name}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 11724 | ▶ | || $class->_throw_exception( MustSupplyPackageNameAndName => params => \%options, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$options{"package_name"} and $options{"name"}
MC/DC50%1/2
$options{"package_name"} and $options{"name"}
$options{"package_name"}
$options{"name"}
Truth table66%2/3
A and B
A= $options{"package_name"}B= $options{"name"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | class => $class | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 11723 | my $self = $class->_new(\%options); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # we don't want this creating | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # a cycle in the code, if not | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # needed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 11723 | weaken($self->{'associated_metaclass'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 11723 | $self->_initialize_body; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 11723 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 11723 | ▶ | sub _new { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=5 SCAR=16.8
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 11723 | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 11723 | ▶ | return Class::MOP::Class->initialize($class)->new_object(@_) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | if $class ne __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 11720 | ▶ | my $params = @_ == 1 ? $_[0] : {@_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | return bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # inherited from Class::MOP::Method | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | body => $params->{body}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # associated_metaclass => $params->{associated_metaclass}, # overridden | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | package_name => $params->{package_name}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | name => $params->{name}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | original_method => $params->{original_method}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # inherited from Class::MOP::Generated | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | is_inline => $params->{is_inline} || 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | definition_context => $params->{definition_context}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # inherited from Class::MOP::Inlined | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | _expected_method_class => $params->{_expected_method_class}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # defined in this subclass | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | options => $params->{options} || {}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | associated_metaclass => $params->{metaclass}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 11720 | ▶ | }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$params->{'is_inline'} || 0
$params->{'options'} || {}
MC/DC0%0/1
$params->{'is_inline'} || 0
$params->{'is_inline'}
MC/DC0%0/1
$params->{'options'} || {}
$params->{'options'}
Truth table50%1/2
A
A= $params->{'is_inline'}
Truth table50%1/2
A
A= $params->{'options'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ## accessors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 12485 | ▶ | sub options { (shift)->{'options'} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 35168 | ▶ | sub associated_metaclass { (shift)->{'associated_metaclass'} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
associated_metaclass: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ## method | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 11723 | ▶ | sub _initialize_body { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_initialize_body: called CC=2 SCAR=7.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 11723 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 11723 | my $method_name = '_generate_constructor_method'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 11723 | ▶ | $method_name .= '_inline' if $self->is_inline; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 11723 | $self->{'body'} = $self->$method_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 12485 | ▶ | sub _eval_environment { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_eval_environment: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 12485 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 12485 | return $self->associated_metaclass->_eval_environment; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub _generate_constructor_method { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_constructor_method: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return sub { Class::MOP::Class->initialize(shift)->new_object(@_) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 12485 | ▶ | sub _generate_constructor_method_inline { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_constructor_method_inline: called CC=2 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 12485 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 12485 | my $meta = $self->associated_metaclass; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 12485 | my @source = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 'sub {', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | $meta->_inline_new_object, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | '}', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 12485 | ▶ | warn join("\n", @source) if $self->options->{debug}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 12485 | ▶ | my $code = try { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 12485 | $self->_compile_code(\@source); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | ▶ | catch { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | my $source = join("\n", @source); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | $self->_throw_exception( CouldNotEvalConstructor => constructor_method => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | source => $source, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | error => $_ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 12485 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 12484 | return $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 459 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # ABSTRACT: Method Meta Object for constructors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||