| 1 | # The entire implementation of Moos (and all its related classes) are defined | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # inside this one file. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 9 | my $VALID_NAME = qr{ ^ [^\W0-9] \w* $ }ix; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | package Moos; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 9 | our $VERSION = '0.30'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 9 | ▶ | if ($] >= 5.010) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | require mro; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | require MRO::Compat; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | our $CAN_HAZ_XS = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | !$ENV{PERL_MOOS_XS_DISABLE} && | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | ▶ | eval{ require Class::XSAccessor; Class::XSAccessor->VERSION("1.07"); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
!$ENV{'PERL_MOOS_XS_DISABLE'} && eval {
do {
require Class::XSAccessor;
'Class::XSAccessor'->VERSION('1.07');
1
}
}
MC/DC0%0/2
!$ENV{'PERL_MOOS_XS_DISABLE'} && eval {
do {
require Class::XSAccessor;
'Class::XSAccessor'->VERSION('1.07');
1
}
}
!$ENV{'PERL_MOOS_XS_DISABLE'}
eval {
do {
require Class::XSAccessor;
'Class::XSAccessor'->VERSION('1.07');
1
}
}
Truth table33%1/3
not(A) && B
A= !$ENV{'PERL_MOOS_XS_DISABLE'}B= eval {
do {
require Class::XSAccessor;
'Class::XSAccessor'->VERSION('1.07');
1
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | use constant default_metaclass => 'Moos::Meta::Class'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | ▶ | use constant default_metarole => 'Moos::Meta::Role'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | ▶ | use constant default_base_class => 'Moos::Object'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 16 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=7 SCAR=19.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # Turn on strict/warnings for caller | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 16 | strict->import; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 16 | warnings->import; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 16 | ▶ | ($_[1]||'') eq -Role and goto \&role_import; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$_[1] || ''
MC/DC100%1/1
$_[1] || ''
$_[1]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 14 | my $package = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # Create/register a metaclass object for the package | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | my $metaclass = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | delete $args{metaclass} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 14 | ▶ | || $class->default_metaclass; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $args{'metaclass'} || $class->default_metaclass
MC/DC0%0/2
delete $args{'metaclass'} || $class->default_metaclass
delete $args{'metaclass'}
$class->default_metaclass
Truth table33%1/3
A || B
A= delete $args{'metaclass'}B= $class->default_metaclass
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 14 | my $meta = $metaclass->initialize($package, %args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # Make calling class inherit from Moos::Object by default | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | my $baseclass = exists $args{base_class} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ? delete $args{base_class} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 14 | ▶ | : $class->default_base_class; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 14 | ▶ | extends($meta, $baseclass) if defined $baseclass; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # Export the 'has', 'extends', and 'with' helper functions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 14 | _export($package, has => \&has, $meta); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 14 | _export($package, extends => \&extends, $meta); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 14 | _export($package, with => \&with, $meta); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # Export the 'blessed' and 'confess' functions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 14 | _export($package, blessed => \&Scalar::Util::blessed); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 14 | _export($package, confess => \&Carp::confess); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # Possibly export some handy debugging stuff | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 14 | ▶ | _export_xxx($package) if $ENV{PERL_MOOS_XXX}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | ▶ | sub role_import { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
role_import: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | my ($class, undef, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | my $package = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Create/register a metaclass object for the package | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | my $metarole = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | delete $args{metarole} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | || $class->default_metarole; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $args{'metarole'} || $class->default_metarole
MC/DC0%0/2
delete $args{'metarole'} || $class->default_metarole
delete $args{'metarole'}
$class->default_metarole
Truth table33%1/3
A || B
A= delete $args{'metarole'}B= $class->default_metarole
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | my $meta = $metarole->initialize($package, %args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # Using 'eval' rather that exporting ensures that this method | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # will not be cleaned up by namespace::autoclean-type things. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | ▶ | eval q{ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
meta: called CC=2 SCAR=11.6
Subroutine
meta: called CC=2 SCAR=11.6
Condition0%0/6
builtin::blessed($_[0]) || $_[0]
builtin::blessed($_[0]) || $_[0]
MC/DC0%0/2
builtin::blessed($_[0]) || $_[0]
builtin::blessed($_[0])
$_[0]
MC/DC0%0/2
builtin::blessed($_[0]) || $_[0]
builtin::blessed($_[0])
$_[0]
Truth table0%0/3
A || B
A= builtin::blessed($_[0])B= $_[0]
Truth table0%0/3
A || B
A= builtin::blessed($_[0])B= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | package }.$package.q{; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | sub meta { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | Moos::Meta::Role->initialize( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | Scalar::Util::blessed($_[0]) || $_[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Export the 'has' helper function | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | _export($package, has => \&has, $meta); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Export the 'blessed' and 'confess' functions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | _export($package, blessed => \&Scalar::Util::blessed); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | _export($package, confess => \&Carp::confess); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # Possibly export some handy debugging stuff | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | ▶ | _export_xxx($package) if $ENV{PERL_MOOS_XXX}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # Now do Role::Tiny's import stuff. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | require Role::Tiny; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | @_ = qw(Role::Tiny); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | goto \&Role::Tiny::import; # preserve caller | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # Attribute generator | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 25 | ▶ | sub has { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 25 | my ($meta, $name) = splice(@_, 0, 2); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 25 | ▶ | $name = [$name] unless ref $name; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 25 | my %args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # Support 2-arg shorthand: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # has foo => 42; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 25 | ▶ | if (@_ % 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | my $default = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | my $sub = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | ▶ | ref($default) eq 'HASH' ? sub {+{%$default}} : | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | ref($default) eq 'ARRAY' ? sub {[@$default]} : | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 6 | ▶ | sub {$default}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | %args = (default => $sub); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 25 | %args = (%args, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Add attributes to meta class object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 25 | $meta->add_attribute($_ => \%args) for @$name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Inheritance maker | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 15 | ▶ | sub extends { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extends: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 15 | my ($meta, @parents) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 15 | for my $parent (@parents) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 15 | eval "require $parent"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 15 | $meta->superclasses(@parents); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | ▶ | sub with { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
with: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | my ($meta, @roles) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | $meta->apply_roles(@roles); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # Use this for exports and meta-exports | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 76 | ▶ | sub _export { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_export: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 76 | my ($package, $name, $code, $meta) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 76 | ▶ | if (defined $meta) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 44 | my $orig = $code; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 27 | ▶ | $code = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 27 | unshift @_, $meta; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 27 | goto &$orig; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 44 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 76 | *{"$package\::$name"} = $code; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # Export the 4 debugging subs from XXX.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub _export_xxx { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_export_xxx: not called CC=2 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my ($package) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | eval "use XXX -with => 'YAML::XS'; 1" or die $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | _export($package, WWW => \&{__PACKAGE__ . '::WWW'}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | _export($package, XXX => \&{__PACKAGE__ . '::XXX'}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | _export($package, YYY => \&{__PACKAGE__ . '::YYY'}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | _export($package, ZZZ => \&{__PACKAGE__ . '::ZZZ'}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # The remainder of this module was heavily inspired by Moose, and tried to do | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # what Moose does, only much less. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | package Moos::Meta::Class; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 9 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 9 | our @ISA = 'Moos::Object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # Store all the Moos meta-class-objects in a private hash, keyed on | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # package/class name: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 9 | my $meta_class_objects = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # Helper method to get class name: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 238 | ▶ | sub name { $_[0]->{package} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 408 | ▶ | sub default_attribute_metaclass { 'Moos::Meta::Attribute' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_attribute_metaclass: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # read-only accessor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 190 | ▶ | sub attribute_metaclass { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attribute_metaclass: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 190 | $_[0]{attribute_metaclass}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 9 | __PACKAGE__->meta->add_attribute( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | attribute_metaclass => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | default => \&default_attribute_metaclass, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | _skip_setup => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # Either looking the existing meta-class-object or register a new one: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 408 | ▶ | sub initialize { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initialize: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 408 | my ($class, $package, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # Class to use to generate attribute accessors, etc | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 408 | ▶ | $args{attribute_metaclass} ||= $class->default_attribute_metaclass; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{"attribute_metaclass"} ||= $class->default_attribute_metaclass
MC/DC0%0/2
$args{"attribute_metaclass"} ||= $class->default_attribute_metaclass
$args{"attribute_metaclass"}
$class->default_attribute_metaclass
Truth table33%1/3
A ||= B
A= $args{"attribute_metaclass"}B= $class->default_attribute_metaclass
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # This is a tiny version of a Moose meta-class-object. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # We really just need a place to keep the attributes. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 408 | ▶ | return $meta_class_objects->{$package} ||= do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$meta_class_objects->{$package} ||= do {
bless {"package", $package, "attributes", {}, "_attributes", [], %args}, $class
}
MC/DC0%0/2
$meta_class_objects->{$package} ||= do {
bless {"package", $package, "attributes", {}, "_attributes", [], %args}, $class
}
$meta_class_objects->{$package}
do {
bless {"package", $package, "attributes", {}, "_attributes", [], %args}, $class
}
Truth table66%2/3
A ||= B
A= $meta_class_objects->{$package}B= do {
bless {"package", $package, "attributes", {}, "_attributes", [], %args}, $class
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 42 | bless { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | package => $package, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # This isn't currently used but matches Moose and is cheap. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | attributes => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # We construct with attribute in order defined. (Unlike Moose) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | _attributes => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | %args, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # Make a new attribute object and add it to both a hash and an array, so that | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # we can preserve the order defined. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 190 | ▶ | sub add_attribute { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_attribute: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 190 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 190 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 190 | ▶ | my %args = @_==1 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 190 | push @{$self->{_attributes}}, ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 190 | $self->{attributes}{$name} = | |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | $self->attribute_metaclass->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | associated_class => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | %args, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my $has_subname = eval { require Sub::Name; 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 19 | ▶ | sub add_method { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_method: called CC=3 SCAR=13.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 19 | my ($self, $name, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 19 | my $pkg = $self->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 19 | ▶ | if (ref $code) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 14 | ▶ | if ($has_subname) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $code = Sub::Name::subname("$pkg\::$name", $code); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | Moos::_export($pkg, $name, $code); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # close over $code | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | eval "package $pkg; sub $name { goto \$code }"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
noos: not called CC=1 SCAR=2.6
Subroutine
array: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | eval "package $pkg; sub $name { $code }"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_attr: called CC=1 SCAR=2.6
Subroutine
bar: not called CC=1 SCAR=2.6
Subroutine
clear_attr1: not called CC=1 SCAR=2.6
Subroutine
clear_attr2: not called CC=1 SCAR=2.6
Subroutine
clear_attr3: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # A tracing wrapper for debugging accessors | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 9 | our $TRACE_EXCLUDE = +{ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 9 | map {($_, 1)} ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 'Some::Module some_accessor', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 'Some::Module some_other_accessor', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | sub _trace_accessor_calls { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trace_accessor_calls: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | require Time::HiRes; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my ($name, $accessor) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my ($pkg, $file, $line, $sub) = caller(0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | unless ($TRACE_EXCLUDE->{"$pkg $name"}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | warn "$pkg $name $line\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | Time::HiRes::usleep(100000); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | goto &$accessor; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 15 | ▶ | sub superclasses { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
superclasses: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 15 | my ($self, @supers) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 15 | ▶ | if (@supers) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 15 | @{"$self->{package}\::ISA"} = @supers; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 15 | return @{"$self->{package}\::ISA"}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 203 | ▶ | sub linearized_isa { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
linearized_isa: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 203 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 203 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 203 | return grep { not $seen{$_}++ } @{ mro::get_linear_isa($self->name) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | sub apply_roles | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_roles: called CC=16 SCAR=43.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | my ($self, @roles) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | my $package = $self->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | require Role::Tiny; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # Load the role modules. (Role::Tiny would do this for us anyway.) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | Role::Tiny::_load_module($_) for @roles; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # If any of them were Moose roles, then Class::MOP will now be | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # available to us. Use it to detect which roles have antlers. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | ▶ | if (my $class_of = 'Class::MOP'->can('class_of')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # Divide list of roles into Moose and non-Moose. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my (@moose, @nonmoose); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | while (@roles) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my $role = shift @roles; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | my $list = $class_of->($role) ? \@moose : \@nonmoose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | push @$list, $role; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if (ref $roles[0] eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | push @$list, shift @roles; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # Apply Moose roles | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | if (@moose and my $apply = 'Moose::Util'->can('apply_all_roles')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@moose and my $apply = "Moose::Util"->can("apply_all_roles")
MC/DC0%0/2
@moose and my $apply = "Moose::Util"->can("apply_all_roles")
@moose
my $apply = "Moose::Util"->can("apply_all_roles")
Truth table0%0/3
A and B
A= @mooseB= my $apply = "Moose::Util"->can("apply_all_roles")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $apply->($package, @moose); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | foreach my $role (@moose) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my $rolemeta = $class_of->($role); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | my @attributes = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | sort { $a->insertion_order <=> $b->insertion_order } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | map { $rolemeta->get_attribute($_) } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | $rolemeta->get_attribute_list; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | foreach my $attr ( @attributes ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $name = $attr->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | my %args = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | lazy => $attr->is_lazy, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | required => $attr->is_required, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | is => $attr->{is}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | _skip_setup => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | for my $arg (qw/ clearer predicate builder default documentation handles trigger /) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my $has = "has_$arg"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | $args{$arg} = $attr->$arg if $attr->$has; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $self->add_attribute($name, \%args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # Allow non-Moose roles to fall through | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | @roles = @nonmoose; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | ▶ | if (@roles) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 1 | 'Role::Tiny'->apply_roles_to_package($package, @roles); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | my @more_roles = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | keys %{ $Role::Tiny::APPLIED_TO{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } @roles; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | foreach my $role (@more_roles) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # Moo::Role stashes its attributes here... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | ▶ | my @attributes = @{ $Role::Tiny::INFO{$role}{attributes} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Role::Tiny::INFO{$role}{'attributes'} || []
MC/DC0%0/1
$Role::Tiny::INFO{$role}{'attributes'} || []
$Role::Tiny::INFO{$role}{'attributes'}
Truth table50%1/2
A
A= $Role::Tiny::INFO{$role}{'attributes'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | ▶ | while (@attributes) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 2 | my $name = shift @attributes; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 2 | my %args = %{ shift @attributes }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 2 | $args{_skip_setup} = 1; # Moo::Role already made accessors | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 2 | $self->add_attribute($name, \%args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # This is where new objects are constructed. (Moose style) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 13 | ▶ | sub new_object { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_object: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 13 | my ($self, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 13 | my $object = $self->_construct_instance($params); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 12 | ▶ | $object->BUILDALL($params) if $object->can('BUILDALL'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 12 | return $object; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 13 | ▶ | sub _construct_instance { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_construct_instance: called CC=13 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 13 | my ($self, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 13 | my $instance = bless {}, $self->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 13 | foreach my $attr ($self->get_all_attributes()) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 26 | my $name = $attr->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 26 | ▶ | next if exists $instance->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 26 | ▶ | if (exists $params->{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 11 | $instance->{$name} = $params->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | elsif (not $attr->{lazy}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 14 | ▶ | if (my $builder = $attr->{builder}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | $builder = "_build_$name" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $builder and $builder eq 1
MC/DC0%0/2
defined $builder and $builder eq 1
defined $builder
$builder eq 1
Truth table0%0/3
A and B
A= defined $builderB= $builder eq 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | if defined $builder && $builder eq "1"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $instance->{$name} = $instance->$builder(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | elsif (my $default = $attr->{default}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 10 | $instance->{$name} = $default->($instance); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 14 | ▶ | if ($attr->{required} and not exists $instance->{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attr->{"required"} and not exists $instance->{$name}
MC/DC50%1/2
$attr->{"required"} and not exists $instance->{$name}
$attr->{"required"}
not exists $instance->{$name}
Truth table66%2/3
A and not(B)
A= $attr->{"required"}B= not exists $instance->{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | confess "missing required attribute '$name'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # Triggers only fire for explicit assignment; not defaults. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 25 | ▶ | if (exists $attr->{trigger} and exists $params->{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $attr->{"trigger"} and exists $params->{$name}
MC/DC100%2/2
exists $attr->{"trigger"} and exists $params->{$name}
exists $attr->{"trigger"}
exists $params->{$name}
Truth table100%3/3
A and B
A= exists $attr->{"trigger"}B= exists $params->{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 1 | $attr->{trigger}->($instance, $params->{$name}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 12 | return $instance; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # Return all the unique attributes in the order defined from the outer class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # inwards: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 13 | ▶ | sub get_all_attributes { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_attributes: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 13 | my (@attrs, %attrs); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 13 | for my $package ($self->linearized_isa) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 27 | my $meta = Moos::Meta::Class->initialize($package); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 27 | for my $attr (@{$meta->{_attributes}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 27 | my $name = $attr->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 27 | ▶ | next if $attrs{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 26 | push @attrs, ($attrs{$name} = $attr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 13 | return @attrs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # Cheap introspection stuff | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | sub get_attribute { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_attribute: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | return $self->{attributes}{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | sub find_attribute_by_name { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_attribute_by_name: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | for ($self->get_all_attributes) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | return $_ if $_->name eq $name; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # Package for roles | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | package Moos::Meta::Role; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 9 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 9 | our @ISA = 'Moos::Meta::Class'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 2 | ▶ | sub add_attribute { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_attribute: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 2 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 2 | ▶ | my %args = @_==1 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 2 | push @{$Role::Tiny::INFO{ $self->name }{attributes}}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | $name => \%args; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 2 | $self->SUPER::add_attribute($name, \%args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # Package for blessed attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | package Moos::Meta::Attribute; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 9 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 9 | ▶ | BEGIN { our @ISA = 'Moos::Object' }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | __PACKAGE__->meta->add_attribute($_, { is=>'ro' }) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 9 | for qw( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | name associated_class is isa coerce does required | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | weak_ref lazy trigger handles builder default clearer | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | predicate documentation _skip_setup | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 178 | ▶ | sub _is_simple { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_simple: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | not ( $_[0]{builder} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | || $_[0]{default} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | || $_[0]{trigger} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | || $ENV{PERL_MOOS_ACCESSOR_CALLS} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 178 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition77%7/9
$_[0]{'builder'} || $_[0]{'default'} || $_[0]{'trigger'} || $ENV{'PERL_MOOS_ACCESSOR_CALLS'}
$_[0]{"builder"} or $_[0]{"default"} or $_[0]{"trigger"}
$_[0]{"builder"} or $_[0]{"default"}
MC/DC50%2/4
$_[0]{'builder'} || $_[0]{'default'} || $_[0]{'trigger'} || $ENV{'PERL_MOOS_ACCESSOR_CALLS'}
$_[0]{"builder"}
$_[0]{"default"}
$_[0]{"trigger"}
$ENV{'PERL_MOOS_ACCESSOR_CALLS'}
Truth table60%3/5
A or B or C || D
A= $_[0]{"builder"}B= $_[0]{"default"}C= $_[0]{"trigger"}D= $ENV{'PERL_MOOS_ACCESSOR_CALLS'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # Not sure why it is necessary to override &new here... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 190 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 190 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 190 | my $self = bless $class->BUILDARGS(@_) => $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 190 | $self->Moos::Object::BUILDALL; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 187 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 190 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=13 SCAR=26.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 190 | shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 190 | ▶ | my $args = @_==1 ? $_[0] : +{@_}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # Massage %args | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 190 | my $name = $args->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | $args->{builder} = "_build_$name" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 190 | ▶ | if defined $args->{builder} && $args->{builder} eq "1"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $args->{"builder"} and $args->{"builder"} eq 1
MC/DC0%0/2
defined $args->{"builder"} and $args->{"builder"} eq 1
defined $args->{"builder"}
$args->{"builder"} eq 1
Truth table33%1/3
A and B
A= defined $args->{"builder"}B= $args->{"builder"} eq 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | $args->{clearer} = $name =~ /^_/ ? "_clear$name" : "clear_$name" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 190 | ▶ | if defined $args->{clearer} && $args->{clearer} eq "1"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $args->{"clearer"} and $args->{"clearer"} eq 1
MC/DC50%1/2
defined $args->{"clearer"} and $args->{"clearer"} eq 1
defined $args->{"clearer"}
$args->{"clearer"} eq 1
Truth table66%2/3
A and B
A= defined $args->{"clearer"}B= $args->{"clearer"} eq 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | $args->{predicate} = $name =~ /^_/ ? "_has$name" : "has_$name" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 190 | ▶ | if defined $args->{predicate} && $args->{predicate} eq "1"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $args->{"predicate"} and $args->{"predicate"} eq 1
MC/DC100%2/2
defined $args->{"predicate"} and $args->{"predicate"} eq 1
defined $args->{"predicate"}
$args->{"predicate"} eq 1
Truth table100%3/3
A and B
A= defined $args->{"predicate"}B= $args->{"predicate"} eq 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | $args->{trigger} = do { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 1 | my ($trigger, $method) = "_trigger_$name"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 2 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 2 | ▶ | $method ||= $_[0]->can($trigger) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$method ||= $_[0]->can($trigger)
MC/DC0%0/2
$method ||= $_[0]->can($trigger)
$method
$_[0]->can($trigger)
Truth table66%2/3
A ||= B
A= $methodB= $_[0]->can($trigger)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | or confess "method $trigger does not exist for class ".ref($_[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 2 | goto $method; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 190 | ▶ | } if defined $args->{trigger} && $args->{trigger} eq "1"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args->{"trigger"} and $args->{"trigger"} eq 1
MC/DC100%2/2
defined $args->{"trigger"} and $args->{"trigger"} eq 1
defined $args->{"trigger"}
$args->{"trigger"} eq 1
Truth table100%3/3
A and B
A= defined $args->{"trigger"}B= $args->{"trigger"} eq 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | $args->{is} = 'rw' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 190 | ▶ | unless defined $args->{is}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 190 | return $args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 190 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 190 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 190 | ▶ | my $metaclass = $self->{associated_class} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 190 | foreach (qw( name builder predicate clearer )) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 756 | ▶ | next if !exists $self->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 198 | ▶ | next if $self->{$_} =~ $VALID_NAME; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | confess sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | "invalid method name '%s' for %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 2 | ▶ | $self->{$_}, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | $_ eq 'name' ? 'attribute' : $_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 188 | ▶ | unless ( $self->{_skip_setup} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 177 | $self->_setup_accessor($metaclass); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 177 | ▶ | $self->_setup_clearer($metaclass) if $self->{clearer}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 177 | ▶ | $self->_setup_predicate($metaclass) if $self->{predicate}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 177 | ▶ | $self->_setup_delegation($metaclass) if $self->{handles}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # Make a Setter/Getter accessor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | sub _setup_accessor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 177 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup_accessor: called CC=11 SCAR=27.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 177 | my ($self, $metaclass) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 177 | my $name = $self->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 177 | ▶ | if ($self->_is_simple) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 163 | ▶ | if ($Moos::CAN_HAZ_XS) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 163 | ▶ | my $type = $self->{is} eq 'ro' ? 'getters' : 'accessors'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | return Class::XSAccessor->import( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | class => $metaclass->{package}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 163 | $type => [$name], | |||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | my $accessor = $self->{is} eq 'ro' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | ? qq{ Carp::confess("cannot set value for read-only accessor '$name'") if \@_ > 1; \$_[0]{'$name'} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | : qq{ \$#_ ? \$_[0]{'$name'} = \$_[1] : \$_[0]{'$name'} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | return $metaclass->add_method($name, $accessor); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 14 | my ($builder, $default) = map $self->{$_}, qw(builder default); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | my $accessor = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | $builder ? sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | $#_ ? $_[0]{$name} = $_[1] : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | exists($_[0]{$name}) ? $_[0]{$name} : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | ($_[0]{$name} = $_[0]->$builder); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | } : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 7 | ▶ | $default ? sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | $#_ ? $_[0]{$name} = $_[1] : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | exists($_[0]{$name}) ? $_[0]{$name} : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 7 | ▶ | ($_[0]{$name} = $default->($_[0])); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 3 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 3 | ▶ | $#_ ? $_[0]{$name} = $_[1] : $_[0]{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 14 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 14 | ▶ | if ($self->{is} eq 'ro') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | my $orig = $accessor; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | $accessor = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | confess "cannot set value for read-only accessor '$name'" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | goto $orig; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | elsif (exists $self->{trigger}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 4 | ▶ | ref $self->{trigger} or confess "trigger for $name is not a reference"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 4 | my $orig = $accessor; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 6 | ▶ | $accessor = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 6 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | $self->{trigger}->( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | @_[0, 1], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 4 | ▶ | exists($_[0]{$name}) ? $_[0]{$name} : (), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 6 | goto $orig; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # Dev debug thing to trace calls to accessor subs. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | $accessor = _trace_accessor_calls($name, $accessor) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 14 | ▶ | if $ENV{PERL_MOOS_ACCESSOR_CALLS}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | # Export the accessor. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 14 | $metaclass->add_method($name, $accessor); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 4 | ▶ | sub _setup_clearer { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup_clearer: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 4 | my ($self, $metaclass) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 4 | my $name = $self->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 4 | ▶ | my $clearer = $self->{clearer} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 4 | $metaclass->add_method($clearer, qq{ delete \$_[0]{'$name'} }); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 1 | ▶ | sub _setup_predicate { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup_predicate: called CC=3 SCAR=12.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 1 | my ($self, $metaclass) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 1 | my $name = $self->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 1 | ▶ | my $predicate = $self->{predicate} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 1 | ▶ | if ($Moos::CAN_HAZ_XS) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | return Class::XSAccessor->import( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | class => $metaclass->{package}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 1 | predicates => { $predicate => $name }, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | $metaclass->add_method($predicate, qq{ exists \$_[0]{'$name'} }); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 2 | ▶ | sub _setup_delegation { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup_delegation: called CC=8 SCAR=21.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 2 | my ($self, $metaclass) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 2 | my $name = $self->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 2 | ▶ | return unless exists $self->{handles}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 2 | my %map; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | %map = %{$self->{handles}} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 2 | ▶ | if Scalar::Util::reftype($self->{handles}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 2 | %map = map { ;$_=>$_ } @{$self->{handles}} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 2 | ▶ | if Scalar::Util::reftype($self->{handles}) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 2 | ▶ | while (my ($local, $remote) = each %map) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 2 | for my $method ($local, $remote) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 3 | ▶ | next if $method =~ $VALID_NAME; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 1 | confess "invalid delegated method name '$method'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 1 | ▶ | if ($self->_is_simple) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 1 | $metaclass->add_method($local, qq{ shift->{$name}->$remote(\@_) }); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | $metaclass->add_method($local, qq{ shift->$name\->$remote(\@_) }); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | # This is the default base class for all Moos classes: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | package Moos::Object; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # Moos constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 13 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 13 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 13 | ▶ | my $real_class = Scalar::Util::blessed($class) || $class; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
builtin::blessed($class) || $class
MC/DC0%0/2
builtin::blessed($class) || $class
builtin::blessed($class)
$class
Truth table33%1/3
A || B
A= builtin::blessed($class)B= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 13 | my $params = $real_class->BUILDARGS(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 13 | return Moos::Meta::Class->initialize($real_class)->new_object($params); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | # A default BUILDARGS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 13 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 13 | shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 13 | ▶ | return +{(@_ and ref($_[0]) eq 'HASH') ? %{$_[0]} : @_}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and ref $_[0] eq "HASH"
MC/DC100%2/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | # A default BUILDALL | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 202 | ▶ | sub BUILDALL { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDALL: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 202 | ▶ | return unless $_[0]->can('BUILD'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 190 | my ($self, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 190 | for my $package (reverse $self->meta->linearized_isa) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 380 | ▶ | if (defined &{"$package\::BUILD"}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 190 | &{"$package\::BUILD"}($self, $params); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | # A Data::Dumper method. (Moose has it. No cost.) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | ▶ | sub dump { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=2 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 9 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | ▶ | local $Data::Dumper::Maxdepth = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | Data::Dumper::Dumper $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | # Retrieve the Moos meta-class-object. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 352 | ▶ | sub meta { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
meta: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 352 | ▶ | Moos::Meta::Class->initialize(Scalar::Util::blessed($_[0]) || $_[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($_[0]) || $_[0]
MC/DC0%0/2
builtin::blessed($_[0]) || $_[0]
builtin::blessed($_[0])
$_[0]
Truth table66%2/3
A || B
A= builtin::blessed($_[0])B= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | sub does { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
does: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | my ($self, $role) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | return 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | if $INC{'Role/Tiny.pm'} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$INC{"Role/Tiny.pm"} and Role::Tiny::does_role($self, $role)
MC/DC0%0/2
$INC{"Role/Tiny.pm"} and Role::Tiny::does_role($self, $role)
$INC{"Role/Tiny.pm"}
Role::Tiny::does_role($self, $role)
Truth table0%0/3
A and B
A= $INC{"Role/Tiny.pm"}B= Role::Tiny::does_role($self, $role)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | && Role::Tiny::does_role($self, $role); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | return 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | if $INC{'Moose/Util.pm'} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$INC{"Moose/Util.pm"} and "Moose::Util"->can("does_role") and Moose::Util::does_role($self, $role)
$INC{"Moose/Util.pm"} and "Moose::Util"->can("does_role")
MC/DC0%0/3
$INC{"Moose/Util.pm"} and "Moose::Util"->can("does_role") and Moose::Util::does_role($self, $role)
$INC{"Moose/Util.pm"}
"Moose::Util"->can("does_role")
Moose::Util::does_role($self, $role)
Truth table0%0/4
A and B and C
A= $INC{"Moose/Util.pm"}B= "Moose::Util"->can("does_role")C= Moose::Util::does_role($self, $role)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | && Moose::Util->can('does_role') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | && Moose::Util::does_role($self, $role); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | ▶ | sub DOES { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DOES: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | my ($self, $role) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | ▶ | my $universal_does = UNIVERSAL->can('DOES') || UNIVERSAL->can('isa'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
'UNIVERSAL'->can('DOES') || 'UNIVERSAL'->can('isa')
MC/DC0%0/2
'UNIVERSAL'->can('DOES') || 'UNIVERSAL'->can('isa')
'UNIVERSAL'->can('DOES')
'UNIVERSAL'->can('isa')
Truth table0%0/3
A || B
A= 'UNIVERSAL'->can('DOES')B= 'UNIVERSAL'->can('isa')
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | ▶ | $self->does($role) or $self->$universal_does($role); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||