| 1 | package MooseX::hasn::t; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 2 | $MooseX::hasn::t::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||
| 5 | 2 | $MooseX::hasn::t::VERSION = '0.003'; | |||||||||||||||||||||||||||||||||||
| 6 | } | ||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use strict qw(subs vars); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||
| 12 | 2 | our @CARP_NOT = qw(Moose::Meta::Method::Overridden); | |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | sub hasn::t | ||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
t: called CC=17 SCAR=33.2
| |||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | my $opts = ref($_[0]) eq 'HASH' ? shift : {}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 20 | 3 | my ($symbol, %args) = @_; | |||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | my $caller = $opts->{caller} || caller; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts->{'caller'} || caller
MC/DC0%0/2
$opts->{'caller'} || caller
$opts->{'caller'}
caller
Truth table66%2/3
A || B
A= $opts->{'caller'}B= caller
| |||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | if (ref $symbol eq 'ARRAY') | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||||
| 25 | 1 | hasn::t({caller=>$caller}, $_, %args) for @$symbol; | |||||||||||||||||||||||||||||||||||
| 26 | 1 | return; | |||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||
| 29 | 2 | my $ERROR = q(Can't locate object method "%s" via package "%s"); | |||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||
| 31 | 2 | my @subs; | |||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | if (my $attr = $caller->meta->find_attribute_by_name($symbol)) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||||||||||
| 34 | 1 | foreach my $role (qw(accessor reader writer predicate clearer initializer)) | |||||||||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||||||||||
| 36 | 6 | my $sub = $attr->$role; | |||||||||||||||||||||||||||||||||||
| 37 | 6 | ▶ | push @subs, $sub if defined $sub && !ref $sub; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $sub and not ref $sub
MC/DC50%1/2
defined $sub and not ref $sub
defined $sub
not ref $sub
Truth table66%2/3
A and not(B)
A= defined $subB= not ref $sub
| |||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | if ($attr->is_required and $attr->has_default) | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$attr->is_required and $attr->has_default
MC/DC0%0/2
$attr->is_required and $attr->has_default
$attr->is_required
$attr->has_default
Truth table33%1/3
A and B
A= $attr->is_requiredB= $attr->has_default
| |||||||||||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||||||||||
| 42 | # OK | ||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||
| 44 | ▶ | elsif ($attr->is_required and exists $args{default}) | |||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$attr->is_required and exists $args{"default"}
MC/DC0%0/2
$attr->is_required and exists $args{"default"}
$attr->is_required
exists $args{"default"}
Truth table33%1/3
A and B
A= $attr->is_requiredB= exists $args{"default"}
| |||||||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | my $init_arg = $attr->init_arg || $symbol; | ||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$attr->init_arg || $symbol
MC/DC0%0/2
$attr->init_arg || $symbol
$attr->init_arg
$symbol
Truth table33%1/3
A || B
A= $attr->init_argB= $symbol
| |||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | unless ($caller->can('BUILDARGS')) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | *{"$caller\::BUILDARGS"} = sub { shift; @_ }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | $caller->meta->add_around_method_modifier(BUILDARGS => sub | ||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||
| 55 | 1 | my ($orig, $class, @args) = @_; | |||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | my $d = ref $args{default} eq 'CODE' ? $args{default}->() : $args{default}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | if (@args==1 and ref $args[0] eq 'HASH') | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@args == 1 and ref $args[0] eq "HASH"
MC/DC0%0/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1
ref $args[0] eq "HASH"
Truth table33%1/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | $args[0]{$init_arg} //= $d; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args[0]{$init_arg} //= $d
MC/DC0%0/2
$args[0]{$init_arg} //= $d
$args[0]{$init_arg}
$d
Truth table0%0/3
A //= B
A= $args[0]{$init_arg}B= $d
| |||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||
| 61 | else | ||||||||||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||||||||||
| 63 | 1 | push @args, $init_arg, $d; | |||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||
| 66 | 1 | $class->$orig(@args); | |||||||||||||||||||||||||||||||||||
| 67 | 1 | }); | |||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||
| 69 | elsif ($attr->is_required) | ||||||||||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||||||||||
| 71 | 0 | croak "can't \"hasn't $symbol\", because $symbol is required and has no default"; | |||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||
| 74 | else | ||||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||||
| 76 | 1 | @subs = $symbol; | |||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||
| 79 | 2 | foreach my $sub (@subs) | |||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||
| 81 | $caller->meta->add_override_method_modifier($sub => sub | ||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||
| 83 | 2 | my ($invocant, @args) = @_; | |||||||||||||||||||||||||||||||||||
| 84 | 2 | ▶ | croak sprintf($ERROR, $sub, (blessed $invocant or $caller)); | ||||||||||||||||||||||||||||||||||
|
Condition33%1/3
builtin::blessed($invocant) || $caller
MC/DC0%0/2
builtin::blessed($invocant) || $caller
builtin::blessed($invocant)
$caller
Truth table33%1/3
A || B
A= builtin::blessed($invocant)B= $caller
| |||||||||||||||||||||||||||||||||||||
| 85 | 3 | }); | |||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||
| 88 | 2 | my $can = $caller->can('can'); | |||||||||||||||||||||||||||||||||||
| 89 | 2 | ▶ | *{"$caller\::can"} = sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 90 | 10 | my ($invocant, $m) = @_; | |||||||||||||||||||||||||||||||||||
| 91 | 10 | ▶ | return if $m ~~ [@subs]; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 92 | 8 | goto $can; | |||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||
| 94 | 2 | } | |||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||
| 96 | 2 | __PACKAGE__ | |||||||||||||||||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||||||||||||||||||