| 1 | package Acme::Has::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | no warnings qw(uninitialized once void numeric); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $AUTHORITY = "cpan:TOBYINK"; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = "0.001"; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use B qw(perlstring); | ||||||||||||||||||||||||||||||||||||||||||||
|
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 | 1 | our %ATTRIBUTES; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | our %VALIDATORS; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | sub _croak ($;@) | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | my $msg = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_croak: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | $Carp::CarpInternal{+__PACKAGE__} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | Carp::croak(sprintf($msg, @_)); | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | BEGIN { *CAN_HAZ_XS = eval 'use Class::XSAccessor 1.18; 1' ? sub(){!!1} : sub(){!!0} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | sub import | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | my %want = map +($_ => 1), @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | if ($want{has}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | *{"$caller\::has"} = sub { unshift @_, __PACKAGE__; goto \&has }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | if ($want{new}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | *{"$caller\::new"} = sub { | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $new = $me->create_constructor("new", class => $_[0], replace => 1); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | goto $new; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | sub has | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has: called CC=5 SCAR=16.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | my ($attrs, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 4 | ▶ | $attrs = [$attrs] unless ref($attrs) eq q(ARRAY); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | ▶ | my $class = $options{class} || caller; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$options{'class'} || caller
MC/DC0%0/2
$options{'class'} || caller
$options{'class'}
caller
Truth table33%1/3
A || B
A= $options{'class'}B= caller
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | delete $VALIDATORS{$class}; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | my @code = "package $class;"; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | for my $a (@$attrs) | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | $ATTRIBUTES{$class}{$a} = +{ %options }; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | push @code, $me->_build_methods($class, $a, $ATTRIBUTES{$class}{$a}); | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | my $str = join "\n", @code, "1;"; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | eval($str) or die("COMPILE ERROR: $@\nCODE:\n$str\n"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
_set_age: called CC=4 SCAR=14.3
Branch: 2 branches
Condition50%3/6
defined $_[1] and not ref $_[1] and &Scalar::Util::looks_like_number($_[1])
defined $_[1] and not ref $_[1]
MC/DC33%1/3
defined $_[1] and not ref $_[1] and &Scalar::Util::looks_like_number($_[1])
defined $_[1]
not ref $_[1]
&Scalar::Util::looks_like_number($_[1])
Truth table50%2/4
A and not(B) and C
A= defined $_[1]B= not ref $_[1]C= &Scalar::Util::looks_like_number($_[1])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | sub assert_valid | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assert_valid: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | my ($class, $hash) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | my @validator = map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | ▶ | $VALIDATORS{$_} ||= $me->_compile_validator($_, $ATTRIBUTES{$_}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Acme::Has::Tiny::VALIDATORS{$_} ||= $me->_compile_validator($_, $Acme::Has::Tiny::ATTRIBUTES{$_})
MC/DC0%0/2
$Acme::Has::Tiny::VALIDATORS{$_} ||= $me->_compile_validator($_, $Acme::Has::Tiny::ATTRIBUTES{$_})
$Acme::Has::Tiny::VALIDATORS{$_}
$me->_compile_validator($_, $Acme::Has::Tiny::ATTRIBUTES{$_})
Truth table66%2/3
A ||= B
A= $Acme::Has::Tiny::VALIDATORS{$_}B= $me->_compile_validator($_, $Acme::Has::Tiny::ATTRIBUTES{$_})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } $me->_find_parents($class); | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | $_->($hash) for @validator; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | return $hash; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | my $default_buildargs = sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | return +{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | ▶ | (@_ == 1 && ref($_[0]) eq q(HASH)) ? %{$_[0]} : @_ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | sub create_constructor | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 3 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_constructor: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 3 | my ($method, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | ▶ | my $class = $options{class} || caller; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$options{'class'} || caller
MC/DC0%0/2
$options{'class'} || caller
$options{'class'}
caller
Truth table33%1/3
A || B
A= $options{'class'}B= caller
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | my $build = $options{build}; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | ▶ | my $buildargs = $options{buildargs} || $default_buildargs; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$options{'buildargs'} || $default_buildargs
MC/DC0%0/2
$options{'buildargs'} || $default_buildargs
$options{'buildargs'}
$default_buildargs
Truth table66%2/3
A || B
A= $options{'buildargs'}B= $default_buildargs
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | my $code = sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | my $self = bless($class->$buildargs(@_), $class); | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | $me->assert_valid($class, $self); | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | ▶ | $self->$build if $options{build}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | ▶ | if ($options{replace}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | no warnings qw(redefine); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | *{"$class\::$method"} = $code; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | use warnings FATAL => qw(redefine); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | *{"$class\::$method"} = $code; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | return $code; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | sub _build_methods | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 4 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_methods: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 4 | my ($class, $attr, $spec) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | my @code; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 4 | ▶ | if ($spec->{is} eq q(rwp)) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | push @code, | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | $me->_build_reader($class, $attr, $spec, $attr), | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | $me->_build_writer($class, $attr, $spec, "_set_$attr"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | elsif ($spec->{is} eq q(rw)) | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | push @code, $me->_build_accessor($class, $attr, $spec, $attr); | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 3 | push @code, $me->_build_reader($class, $attr, $spec, $attr); | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 4 | ▶ | if ($spec->{predicate} eq q(1)) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | push @code, $me->_build_predicate($class, $attr, $spec, "has_$attr"); | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | elsif ($spec->{predicate}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | push @code, $me->_build_predicate($class, $attr, $spec, $spec->{predicate}); | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | return @code; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | sub _build_reader | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 4 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_reader: called CC=6 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | my ($class, $attr, $spec, $method) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 4 | my $builder_name; | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | 4 | ▶ | if ($spec->{builder} eq q(1)) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $builder_name = "_build_$attr"; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | elsif (ref($spec->{builder}) eq q(CODE)) | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $builder_name = "_build_$attr"; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | *{"$class\::$builder_name"} = $spec->{builder}; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | elsif ($spec->{builder}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $builder_name = $spec->{builder}; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 4 | ▶ | if (CAN_HAZ_XS and not $builder_name) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 4 | "Class::XSAccessor"->import(class => $class, getters => { $method => $attr }); | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | return $builder_name | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ? sprintf('sub %s { $_[0]{%s} ||= $_[0]->%s }', $method, perlstring($attr), $builder_name) | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | : sprintf('sub %s { $_[0]{%s} }', $method, perlstring($attr)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | sub _build_predicate | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 2 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_predicate: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 2 | my ($class, $attr, $spec, $method) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 2 | if (CAN_HAZ_XS) | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 2 | "Class::XSAccessor"->import(class => $class, exists_predicates => { $method => $attr }); | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | return sprintf('sub %s { exists $_[0]{%s} }', $method, perlstring($attr)); | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | sub _build_writer | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_writer: called CC=7 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | my ($class, $attr, $spec, $method) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | my $inlined; | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | my $isa = $spec->{isa}; | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | ▶ | if (blessed($isa) and $isa->isa('Type::Tiny') and $isa->can_be_inlined) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
builtin::blessed($isa) and $isa->isa("Type::Tiny") and $isa->can_be_inlined
builtin::blessed($isa) and $isa->isa("Type::Tiny")
MC/DC0%0/3
builtin::blessed($isa) and $isa->isa("Type::Tiny") and $isa->can_be_inlined
builtin::blessed($isa)
$isa->isa("Type::Tiny")
$isa->can_be_inlined
Truth table25%1/4
A and B and C
A= builtin::blessed($isa)B= $isa->isa("Type::Tiny")C= $isa->can_be_inlined
| |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | $inlined = $isa->inline_assert('$_[1]'); | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | elsif ($isa) | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $inlined = sprintf('$Acme::Has::Tiny::ATTRIBUTES{%s}{%s}{isa}->($_[1]);', perlstring($class), perlstring($attr)); | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | ▶ | if (CAN_HAZ_XS and not $inlined) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | "Class::XSAccessor"->import(class => $class, setters => { $method => $attr }); | |||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | ▶ | return defined($inlined) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | ? sprintf('sub %s { %s; $_[0]{%s} = $_[1] }', $method, $inlined, perlstring($attr)) | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | : sprintf('sub %s { $_[0]{%s} = $_[1] }', $method, perlstring($attr)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | sub _build_accessor | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_accessor: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my ($class, $attr, $spec, $method) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $inlined; | |||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $isa = $spec->{isa}; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if (blessed($isa) and $isa->can_be_inlined) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
builtin::blessed($isa) and $isa->can_be_inlined
MC/DC0%0/2
builtin::blessed($isa) and $isa->can_be_inlined
builtin::blessed($isa)
$isa->can_be_inlined
Truth table0%0/3
A and B
A= builtin::blessed($isa)B= $isa->can_be_inlined
| |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $inlined = $isa->inline_assert('$_[1]'); | |||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | elsif ($isa) | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $inlined = sprintf('$Acme::Has::Tiny::ATTRIBUTES{%s}{%s}{isa}->($_[1]);', perlstring($class), perlstring($attr)); | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if (CAN_HAZ_XS and not $inlined) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | "Class::XSAccessor"->import(class => $class, accessors => { $method => $attr }); | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | return defined($inlined) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | ? sprintf('sub %s { return $_[0]{%s} unless @_; %s; $_[0]{%s} = $_[1] }', $method, perlstring($attr), $inlined, perlstring($attr)) | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | : sprintf('sub %s { return $_[0]{%s} unless @_; $_[0]{%s} = $_[1] }', $method, perlstring($attr), perlstring($attr)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | sub _compile_validator | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compile_validator: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 2 | my $code = join "\n" => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | "#line 1 \"validator(Acme::Has::Tiny)\"", | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | "package $_[0];", | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 'sub {', | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 'my $self = $_[0];', | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | $me->_build_validator_parts(@_), | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 'return $self;', | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | '}', | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 2 | eval $code; | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | sub _build_validator_parts | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 2 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_validator_parts: called CC=7 SCAR=21.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 2 | my ($class, $attributes) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 2 | my @code; | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | 2 | for my $a (sort keys %$attributes) | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 4 | my $spec = $attributes->{$a}; | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 4 | ▶ | if ($spec->{default}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | push @code, sprintf( | |||||||||||||||||||||||||||||||||||||||||||||
| 286 | 'exists($self->{%s}) or $self->{%s} = $Acme::Has::Tiny::ATTRIBUTES{%s}{%s}{default}->();', | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | map perlstring($_), $a, $a, $class, $a, | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | elsif ($spec->{required}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 2 | push @code, sprintf( | |||||||||||||||||||||||||||||||||||||||||||||
| 293 | 'exists($self->{%s}) or Acme::Has::Tiny::_croak("Attribute %%s is required by %%s", %s, %s);', | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | map perlstring($_), $a, $a, $class, | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 4 | my $isa = $spec->{isa}; | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | 4 | ▶ | if (blessed($isa) and $isa->can_be_inlined) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
builtin::blessed($isa) and $isa->can_be_inlined
MC/DC0%0/2
builtin::blessed($isa) and $isa->can_be_inlined
builtin::blessed($isa)
$isa->can_be_inlined
Truth table33%1/3
A and B
A= builtin::blessed($isa)B= $isa->can_be_inlined
| |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | push @code, ( | |||||||||||||||||||||||||||||||||||||||||||||
| 302 | sprintf('if (exists($self->{%s})) {', $a), | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | $isa->inline_assert(sprintf '$self->{%s}', perlstring($a)), | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | '}', | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | elsif ($isa) | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | push @code, ( | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | sprintf('if (exists($self->{%s})) {', $a), | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | sprintf('$Acme::Has::Tiny::ATTRIBUTES{%s}{%s}{isa}->($self->{%s});', map perlstring($_), $class, $a, $a), | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | '}', | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 2 | return @code; | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | sub _find_parents | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 3 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_parents: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 3 | my $class = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 3 | ▶ | if (eval { require mro } or eval { require MRO::Compat }) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
eval {
do {
require mro
}
} or eval {
do {
require MRO::Compat
}
}
MC/DC0%0/2
eval {
do {
require mro
}
} or eval {
do {
require MRO::Compat
}
}
eval {
do {
require mro
}
}
eval {
do {
require MRO::Compat
}
}
Truth table33%1/3
A or B
A= eval {
do {
require mro
}
}B= eval {
do {
require MRO::Compat
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 3 | return @{ mro::get_linear_isa($class) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | require Class::ISA; | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | return Class::ISA::self_and_super_path($class); | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||