| 1 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package MooseX::AttributeTags; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.005'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Data::OptList qw(mkopt); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | my $subname = eval { require Sub::Name; 'Sub::Name'->can('subname') } | |||||||||||||||||||||||||||
| 15 | 1 | ▶ | || do { require Sub::Util; 'Sub::Util'->can('set_subname') }; | ||||||||||||||||||||||||||
|
Condition33%1/3
eval {
do {
require Sub::Name;
'Sub::Name'->can('subname')
}
} || do {
require Sub::Util;
'Sub::Util'->can('set_subname')
}
MC/DC0%0/2
eval {
do {
require Sub::Name;
'Sub::Name'->can('subname')
}
} || do {
require Sub::Util;
'Sub::Util'->can('set_subname')
}
eval {
do {
require Sub::Name;
'Sub::Name'->can('subname')
}
}
do {
require Sub::Util;
'Sub::Util'->can('set_subname')
}
Truth table33%1/3
A || B
A= eval {
do {
require Sub::Name;
'Sub::Name'->can('subname')
}
}B= do {
require Sub::Util;
'Sub::Util'->can('set_subname')
}
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | my $yah = 1; # avoid exported subs becoming constants | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub import | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 21 | 1 | my $caller = caller; | |||||||||||||||||||||||||||
| 22 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 23 | 1 | my $opts = mkopt(\@_); | |||||||||||||||||||||||||||
| 24 | 1 | my $prole = $class->_prole; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | for (@$opts) | |||||||||||||||||||||||||||
| 27 | { | ||||||||||||||||||||||||||||
| 28 | 3 | my ($traitname, $traitdesc) = @$_; | |||||||||||||||||||||||||||
| 29 | 3 | ▶ | $traitdesc ||= []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$traitdesc ||= []
MC/DC100%1/1
$traitdesc ||= []
$traitdesc
Truth table100%2/2
A
A= $traitdesc
| |||||||||||||||||||||||||||||
| 30 | 3 | ▶ | ref($traitdesc) eq 'ARRAY' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | or croak("Expected arrayref, not $traitdesc; stopped"); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 3 | my %attrs; | |||||||||||||||||||||||||||
| 34 | 3 | my $inner_opts = mkopt($traitdesc); | |||||||||||||||||||||||||||
| 35 | 3 | for (@$inner_opts) | |||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | 4 | my ($attrname, $attrdesc) = @$_; | |||||||||||||||||||||||||||
| 38 | 4 | $attrs{$attrname} = $class->_canonicalize_attribute_spec($attrdesc); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 3 | my $traitqname = sprintf('%s::%s', $caller, $traitname); | |||||||||||||||||||||||||||
| 42 | 3 | my $trait = $prole->generate_role( | |||||||||||||||||||||||||||
| 43 | package => $traitqname, | ||||||||||||||||||||||||||||
| 44 | parameters => { attributes => \%attrs }, | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 3 | ▶ | my $coderef = $subname->($traitqname, sub () { $traitqname if $yah }); | ||||||||||||||||||||||||||
|
Subroutine
Baz: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 3 | *$traitqname = $coderef; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub _prole | ||||||||||||||||||||||||||||
| 54 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_prole: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 1 | require MooseX::AttributeTags::PRole; | |||||||||||||||||||||||||||
| 56 | 1 | Class::MOP::class_of('MooseX::AttributeTags::PRole'); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub _canonicalize_attribute_spec | ||||||||||||||||||||||||||||
| 60 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_canonicalize_attribute_spec: called CC=7 SCAR=25.1
| |||||||||||||||||||||||||||||
| 61 | 4 | shift; | |||||||||||||||||||||||||||
| 62 | 4 | my $spec = $_[0]; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 4 | ▶ | return [ is => 'ro' ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | unless defined $spec; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 4 | ▶ | return $spec | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | if ref $spec eq 'ARRAY'; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | ▶ | return [ %$spec ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | if ref $spec eq 'HASH'; | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | ▶ | return [ is => 'ro', lazy => 1, default => $spec ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | if ref $spec eq 'CODE'; | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | return [ is => 'ro', isa => $spec ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($spec) and $spec->isa("Moose::Meta::TypeConstraint")
MC/DC0%0/2
builtin::blessed($spec) and $spec->isa("Moose::Meta::TypeConstraint")
builtin::blessed($spec)
$spec->isa("Moose::Meta::TypeConstraint")
Truth table0%0/3
A and B
A= builtin::blessed($spec)B= $spec->isa("Moose::Meta::TypeConstraint")
| |||||||||||||||||||||||||||||
| 77 | if blessed($spec) && $spec->isa('Moose::Meta::TypeConstraint'); | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | croak("Expected coderef/arrayref/hashref/constraint, not $spec; stopped"); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | 1; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||