MultiMethods.pm

filter: Statementstmt 100% 94 / 94 Branchbran 61.1% 11 / 18 Conditioncond 40.0% 4 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 95.6% 22 / 23 Podpod n/a totaltotal 86.7% 131 / 151 CC 15 SCAR 12.0
CC
15
Cov
89%
__ANON__
7.5
parse
7.5
__ANON__
2.0
CRAP 3.3
↑ Summary MultiMethods/Meta/Method.pm »
1 package MooseX::MultiMethods;
2 6 our $VERSION = '0.10';
3 # ABSTRACT: Multi Method Dispatch based on Moose type constraints
4  
5 6 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Devel::Declare ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use MooseX::Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Sub::Install qw/install_sub/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use MooseX::Types::Moose qw/HashRef ClassName/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use aliased 'Devel::Declare::Context::Simple' => 'DDContext';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use aliased 'MooseX::MultiMethods::Meta::Method' => 'MetaMethod';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 6 has _dd_context => (
17 is => 'ro',
18 isa => DDContext,
19 lazy => 1,
20 builder => '_build_dd_context',
21 handles => qr/.*/,
22 );
23  
24 has _dd_init_args => (
25 is => 'rw',
26 isa => HashRef,
27 30 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
28 6 );
29  
30 6 has class => (
31 is => 'ro',
32 isa => ClassName,
33 required => 1,
34 );
35  
36 6 ▶method BUILD ($args) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BUILD: called CC=1 SCAR=0.0
37 4 $self->_dd_init_args($args);
38 6 }
39  
40 6 ▶method _build_dd_context {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _build_dd_context: called CC=1 SCAR=0.0
41 28 return DDContext->new(%{ $self->_dd_init_args });
42 6 }
43  
44 6 ▶method import (ClassName $class:) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
45 7 my $setup_class = caller;
46 7 $class->setup_for($setup_class);
47 6 }
48  
49 6 ▶method setup_for (ClassName $class: ClassName $setup_class, HashRef $args = {}) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine setup_for: called CC=2 SCAR=7.0
50 Devel::Declare->setup_for($setup_class, {
51 'multi' => {
52 30 ▶ const => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
53 30 my $self = $class->new({ class => $setup_class, %{ $args } });
54 30 $self->init(@_);
55 30 return $self->parse;
56 },
57 },
58 7 });
59  
60 install_sub({
61 0 ▶ code => sub {},
Subroutine __ANON__: not called CC=1 SCAR=0.0
62 7 into => $setup_class,
63 as => 'multi',
64 });
65  
66 7 ▶ MooseX::Method::Signatures->setup_for($setup_class)
Branch: 2 branches
BranchTrueFalseTotal
unless $setup_class->can("method") 7 0 7
unless $setup_class->can("method") 0 11 11
67 unless $setup_class->can('method');
68 6 }
69  
70 6 ▶method parse {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine parse: called CC=7 SCAR=20.1
71 19 $self->skip_declarator;
72 19 $self->skipspace;
73  
74 19 my $thing = $self->strip_name;
75 19 ▶ confess "expected 'method', got '${thing}'"
Branch: 2 branches
BranchTrueFalseTotal
unless $thing eq "method" 0 19 19
unless $thing eq "method" 0 11 11
76 unless $thing eq 'method';
77  
78 19 $self->skipspace;
79  
80 19 my $name = $self->strip_name;
81 19 ▶ confess "anonymous multi methods not allowed"
Branch: 2 branches
BranchTrueFalseTotal
unless defined $name and length $name 0 19 19
unless defined $name and length $name 1 10 11
Condition33%2/6
defined $name and length $name
!ll&&!rl&&r
0019
defined $name and length $name
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $name and length $name
defined $name length $name
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
82 unless defined $name && length $name;
83  
84 19 ▶ my $proto = $self->strip_proto || '';
Condition50%2/4
$self->strip_proto || ''
l!l
190
$self->strip_proto || ''
l!l
110
MC/DC0%0/1
$self->strip_proto || ''
$self->strip_proto
MC/DC0%0/1
$self->strip_proto || ''
$self->strip_proto
Truth table50%1/2
A
A= $self->strip_proto
Aresult
11
00
Truth table50%1/2
A
A= $self->strip_proto
Aresult
11
00
85 19 my $proto_variant = MooseX::Method::Signatures::Meta::Method->wrap(
86 signature => "(${proto})",
87 package_name => $self->get_curstash_name,
88 name => $name,
89 );
90  
91 19 $self->inject_if_block($self->scope_injector_call . $proto_variant->injectable_code, 'sub');
92  
93 19 my $meta = Class::MOP::class_of($self->class);
94 19 my $meta_method = $meta->get_method($name);
95 19 ▶ unless ($meta_method) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($meta_method) 6 13 19
unless ($meta_method) 0 11 11
96 6 $meta_method = MetaMethod->new(
97 name => $name,
98 package_name => $self->class,
99 );
100 6 $meta->add_method($name => $meta_method);
101 }
102  
103 19 ▶ confess "method '${name}' is already defined"
Branch: 1 branch
BranchTrueFalseTotal
unless $meta_method->isa("MooseX::MultiMethods::Meta::Method") 0 19 19
104 unless $meta_method->isa(MetaMethod);
105  
106 30 ▶ $self->shadow(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
107 30 my $variant = $proto_variant->reify(actual_body => $_[0]);
108 30 $meta_method->add_variant($variant->type_constraint => $variant);
109 19 });
110 6 }
111  
112 6 1;
113  
114 __END__
↑ Summary MultiMethods/Meta/Method.pm »