StrictConstructor.pm

filter: Statementstmt 94.4% 34 / 36 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 92.4% 49 / 53 CC 6 SCAR 8.6
CC
6
Cov
91%
import
4.2
_apply_role
3.0
BEGIN
1.0
CRAP 2.4
« StrictConstructor/Role/BuildAll.pm ↑ Summary StrictConstructor/Role/Constructor/Late.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package MooX::StrictConstructor;
4  
5 2 our $VERSION = '0.013';
6  
7 2 ▶use Moo ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Moo::Role ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Moo::_Utils qw(_install_modifier);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 ▶sub import {
Subroutine import: called CC=4 SCAR=14.5
13 6 my $class = shift;
14 6 my $target = caller;
15 6 my $late;
16 6 for my $arg (@_) {
17 1 ▶ if ($arg eq '-late') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq '-late') { } 1 0 1
18 1 $late = 1;
19 }
20 else {
21 0 Carp::croak("Unknown option $arg");
22 }
23 }
24 6 ▶ unless ( Moo->is_class($target) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Moo"->is_class($target)) 0 6 6
25 0 Carp::croak("MooX::StrictConstructor can only be used on Moo classes.");
26 }
27  
28 6 _apply_role($target, $late);
29  
30 2 ▶ _install_modifier($target, 'after', 'extends', sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
31 2 _apply_role($target, $late);
32 6 });
33 }
34  
35 8 ▶sub _apply_role {
Subroutine _apply_role: called CC=3 SCAR=11.0
36 8 my ($target, $late) = @_;
37 8 my $con = Moo->_constructor_maker_for($target); ## no critic (Subroutines::ProtectPrivateSubs)
38 8 ▶ my $role = $late ? 'MooX::StrictConstructor::Role::Constructor::Late'
Branch: 1 branch
BranchTrueFalseTotal
$late ? : 1 7 8
39 : 'MooX::StrictConstructor::Role::Constructor';
40 8 ▶ Moo::Role->apply_roles_to_object($con, $role)
Branch: 1 branch
BranchTrueFalseTotal
unless Moo::Role::does_role($con, $role) 7 1 8
41 unless Moo::Role::does_role($con, $role);
42 }
43  
44 2 1;
45  
46 __END__
« StrictConstructor/Role/BuildAll.pm ↑ Summary StrictConstructor/Role/Constructor/Late.pm »