lib/Mite/Trait/HasConstructor.pm.mite.pm

filter: Statementstmt 69.1% 65 / 94 Branchbran 20.0% 4 / 20 Conditioncond 12.5% 2 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 52.3% 11 / 21 Podpod 0.0% 0 / 2 totaltotal 50.3% 82 / 163 CC 19 SCAR 29.5
CC
19
Cov
55%
DOES
72.0
__META__
14.3
__FINALIZE_APPLICATION__
9.7
CRAP 19.1
« lib/Mite/Trait/HasMOP.pm.mite.pm ↑ Summary lib/Mite/Trait/HasDestructor.pm.mite.pm »
1 {
2  
3 117 package Mite::Trait::HasConstructor;
4 117 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 117 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 117 ▶ no warnings qw( once void );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 117 our $USES_MITE = "Mite::Role";
9 117 our $MITE_SHIM = "Mite::Shim";
10 117 our $MITE_VERSION = "0.013000";
11  
12 # Mite keywords
13 117 ▶ BEGIN {
Subroutine BEGIN: called CC=1 SCAR=1.2
14 117 my ( $SHIM, $CALLER ) =
15 ( "Mite::Shim", "Mite::Trait::HasConstructor" );
16 (
17 *after, *around, *before,
18 *field, *has, *param,
19 *requires, *signature_for, *with
20 )
21 117 = do {
22  
23 package Mite::Shim;
24 117 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 (
26 0 ▶ sub { $SHIM->HANDLE_after( $CALLER, "role", @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 117 ▶ sub { $SHIM->HANDLE_around( $CALLER, "role", @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
28 0 ▶ sub { $SHIM->HANDLE_before( $CALLER, "role", @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 0 ▶ sub { $SHIM->HANDLE_has( $CALLER, field => @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 ▶ sub { $SHIM->HANDLE_has( $CALLER, has => @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 ▶ sub { $SHIM->HANDLE_has( $CALLER, param => @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 117 ▶ sub { },
Subroutine __ANON__: called CC=1 SCAR=0.0
33 0 ▶ sub { $SHIM->HANDLE_signature_for( $CALLER, "role", @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 ▶ sub { $SHIM->HANDLE_with( $CALLER, @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 117 );
36 };
37 }
38  
39 # Mite imports
40 117 ▶ BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
41 117 require Scalar::Util;
42 117 *STRICT = \&Mite::Shim::STRICT;
43 117 *bare = \&Mite::Shim::bare;
44 117 *blessed = \&Scalar::Util::blessed;
45 117 *carp = \&Mite::Shim::carp;
46 117 *confess = \&Mite::Shim::confess;
47 117 *croak = \&Mite::Shim::croak;
48 117 *false = \&Mite::Shim::false;
49 117 *guard = \&Mite::Shim::guard;
50 117 *lazy = \&Mite::Shim::lazy;
51 117 *lock = \&Mite::Shim::lock;
52 117 *ro = \&Mite::Shim::ro;
53 117 *rw = \&Mite::Shim::rw;
54 117 *rwp = \&Mite::Shim::rwp;
55 117 *true = \&Mite::Shim::true;
56 117 *unlock = \&Mite::Shim::unlock;
57 }
58  
59 # Gather metadata for constructor and destructor
60 0 ▶ sub __META__ {
Subroutine __META__: not called CC=4 SCAR=26.6
61 117 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
62 0 my $class = shift;
63 0 ▶ $class = ref($class) || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
64 0 my $linear_isa = mro::get_linear_isa($class);
65 return {
66 BUILD => [
67 0 ▶ map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
Branch: 1 branch
BranchTrueFalseTotal
*{$_;}{'CODE'} ? : 0 0 0
68 0 map { "$_\::BUILD" } reverse @$linear_isa
69 ],
70 DEMOLISH => [
71 0 ▶ map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
Branch: 1 branch
BranchTrueFalseTotal
*{$_;}{'CODE'} ? : 0 0 0
72 0 map { "$_\::DEMOLISH" } @$linear_isa
73 ],
74 HAS_BUILDARGS => $class->can('BUILDARGS'),
75 HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'),
76 };
77 }
78  
79 # See UNIVERSAL
80 0 ▶ sub DOES {
Subroutine DOES: not called CC=8 SCAR=42.8
Pod undocumented
81 0 my ( $self, $role ) = @_;
82 0 our %DOES;
83 0 ▶ return $DOES{$role} if exists $DOES{$role};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Mite::Trait::HasConstructor::DOES{$role} 0 0 0
84 0 ▶ return 1 if $role eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if $role eq __PACKAGE__ 0 0 0
85 0 ▶ if ( $INC{'Moose/Util.pm'}
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moose/Util.pm"} and my $meta = Moose::Util::find_meta(ref $self || $self)) 0 0 0
Condition0%0/6
$INC{"Moose/Util.pm"} and my $meta = Moose::Util::find_meta(ref $self || $self)
!ll&&!rl&&r
000
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$INC{"Moose/Util.pm"} and my $meta = Moose::Util::find_meta(ref $self || $self)
$INC{"Moose/Util.pm"} my $meta = Moose::Util::find_meta(ref $self || $self)
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A and B
A= $INC{"Moose/Util.pm"}B= my $meta = Moose::Util::find_meta(ref $self || $self)
ABresult
0X0
100
111
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
86 and my $meta = Moose::Util::find_meta( ref $self or $self ) )
87 {
88 0 ▶ $meta->can('does_role') and $meta->does_role($role) and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$meta->can("does_role") and $meta->does_role($role) and return 1 0 0 0
Condition0%0/3
$meta->can("does_role") and $meta->does_role($role)
!ll&&!rl&&r
000
MC/DC0%0/2
$meta->can("does_role") and $meta->does_role($role)
$meta->can("does_role") $meta->does_role($role)
Truth table0%0/3
A and B
A= $meta->can("does_role")B= $meta->does_role($role)
ABresult
0X0
100
111
89 }
90 0 return $self->SUPER::DOES($role);
91 }
92  
93 # Alias for Moose/Moo-compatibility
94 0 ▶ sub does {
Subroutine does: not called CC=1 SCAR=6.9
Pod undocumented
95 0 shift->DOES(@_);
96 }
97  
98 # Callback which classes consuming this role will call
99 117 ▶ sub __FINALIZE_APPLICATION__ {
Subroutine __FINALIZE_APPLICATION__: called CC=9 SCAR=22.7
100 117 my ( $me, $target, $args ) = @_;
101 117 our ( %CONSUMERS, @METHOD_MODIFIERS );
102  
103 # Ensure a given target only consumes this role once.
104 117 ▶ if ( exists $CONSUMERS{$target} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Mite::Trait::HasConstructor::CONSUMERS{$target}) 0 117 117
105 0 return;
106 }
107 117 $CONSUMERS{$target} = 1;
108  
109 117 ▶ my $type = do { no strict 'refs'; ${"$target\::USES_MITE"} };
Subroutine BEGIN: called CC=1 SCAR=0.0
110 117 ▶ return if $type ne 'Mite::Class';
Branch: 1 branch
BranchTrueFalseTotal
if $type ne "Mite::Class" 0 117 117
111  
112 117 my @missing_methods;
113 117 ▶ @missing_methods = grep( !$target->can($_),
Branch: 1 branch
BranchTrueFalseTotal
@missing_methods = grep((!$target->can($_)), "_compile_meta", "_get_parent", "compilation_stages", "linear_isa") and croak("$me requires $target to implement methods: " . join(", ", @missing_methods)) 0 117 117
114 "_compile_meta", "_get_parent",
115 "compilation_stages", "linear_isa" )
116 and croak( "$me requires $target to implement methods: " . join q[, ],
117 @missing_methods );
118  
119 117 my @roles = ();
120 117 ▶ my %nextargs = %{ $args || {} };
Condition50%1/2
$args || {}
l!l
0117
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
121 117 ▶ ( $nextargs{-indirect} ||= 0 )++;
Condition50%1/2
$nextargs{"-indirect"} ||= 0
l!l
0117
MC/DC0%0/1
$nextargs{"-indirect"} ||= 0
$nextargs{"-indirect"}
Truth table50%1/2
A
A= $nextargs{"-indirect"}
Aresult
11
00
122 117 ▶ croak("PANIC!") if $nextargs{-indirect} > 100;
Branch: 1 branch
BranchTrueFalseTotal
if $nextargs{"-indirect"} > 100 0 117 117
123 117 for my $role (@roles) {
124 0 $role->__FINALIZE_APPLICATION__( $target, {%nextargs} );
125 }
126  
127 117 my $shim = "Mite::Shim";
128 117 for my $modifier_rule (@METHOD_MODIFIERS) {
129 117 my ( $modification, $names, $coderef ) = @$modifier_rule;
130 117 my $handler = "HANDLE_$modification";
131 117 $shim->$handler( $target, "class", $names, $coderef );
132 }
133  
134 117 return;
135 }
136  
137 117 1;
138 }
« lib/Mite/Trait/HasMOP.pm.mite.pm ↑ Summary lib/Mite/Trait/HasDestructor.pm.mite.pm »