blib/lib/MooX/Role/Reconstruct.pm

filter: Statementstmt 100% 34 / 34 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 88.6% 47 / 53 CC 7 SCAR 10.1
CC
7
Cov
91%
import
4.1
__ANON__
4.0
BEGIN
1.0
CRAP 2.7
↑ Summary
1 package MooX::Role::Reconstruct;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 our $VERSION = 'v0.1.2';
9  
10 11 ▶use Sub::Quote;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use Sub::Defer;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 10 ▶sub import {
Subroutine import: called CC=4 SCAR=14.0
15 10 my $target = shift;
16 10 ▶ my %args = @_ ? (@_) : ( method => 'reconstruct' );
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 10 10
17  
18 10 my $method = delete( $args{method} );
19  
20 die 'MooX::Role::Reconstruct can only be used on Moo classes.'
21 10 ▶ unless $Moo::MAKERS{$target} && $Moo::MAKERS{$target}{is_class};
Branch: 1 branch
BranchTrueFalseTotal
unless $Moo::MAKERS{$target} and $Moo::MAKERS{$target}{"is_class"} 0 10 10
Condition33%1/3
$Moo::MAKERS{$target} and $Moo::MAKERS{$target}{"is_class"}
!ll&&!rl&&r
0010
MC/DC0%0/2
$Moo::MAKERS{$target} and $Moo::MAKERS{$target}{"is_class"}
$Moo::MAKERS{$target} $Moo::MAKERS{$target}{"is_class"}
Truth table33%1/3
A and B
A= $Moo::MAKERS{$target}B= $Moo::MAKERS{$target}{"is_class"}
ABresult
0X0
100
111
22  
23 10 my $con = Moo->_constructor_maker_for($target);
24  
25 defer_sub(
26 10 ▶ "${target}::${method}" => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
27  
28 # don't alter the original specs if called before new
29 10 my %spec;
30 10 for ( keys( %{ $con->{attribute_specs} } ) ) {
31 22 $spec{$_} = { %{ $con->{attribute_specs}{$_} } };
32 }
33 10 for ( grep exists( $spec{$_}{init_arg} ), keys(%spec) )
34 {
35 19 ▶ delete($spec{$_}{init_arg}) unless $spec{$_}{keep_init};
Branch: 1 branch
BranchTrueFalseTotal
unless $spec{$_}{"keep_init"} 14 5 19
36 }
37 10 unquote_sub $con->generate_method(
38 $target, $method, \%spec, { no_install => 1 }
39 );
40 }
41 10 );
42  
43 10 return;
44 }
45  
46 11 1;
47  
48 __END__
↑ Summary