blib/lib/MooseX/Attribute/TypeConstraint/CustomizeFatal.pm

filter: Statementstmt 91.6% 44 / 48 Branchbran 71.4% 10 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 85.9% 67 / 78 CC 9 SCAR 17.3
CC
9
Cov
86%
__ANON__
10.8
__ANON__
1.0
BEGIN
1.0
CRAP 5.6
↑ Summary
1 package MooseX::Attribute::TypeConstraint::CustomizeFatal;
2 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 $MooseX::Attribute::TypeConstraint::CustomizeFatal::AUTHORITY = 'cpan:AVAR';
4 }
5 {
6 2 $MooseX::Attribute::TypeConstraint::CustomizeFatal::VERSION = '0.03';
7 }
8 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use MooseX::Types::Moose ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use MooseX::Types -declare => [ qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 TypeConstraintCustomizeFatalAction
13 2 ) ];
14 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 enum TypeConstraintCustomizeFatalAction, [ qw(
17 error
18 warning
19 default
20 default_no_warning
21 ) ];
22  
23 has on_typeconstraint_failure => (
24 is => 'ro',
25 isa => TypeConstraintCustomizeFatalAction,
26 default => 'error',
27 2 documentation => "What should we do when a typeconstraint fails? Possible values: " . join(", ", @{ TypeConstraintCustomizeFatalAction->values }),
28 );
29  
30 30 ▶around _coerce_and_verify => sub {
Subroutine __ANON__: called CC=1 SCAR=0.1
31 30 my $orig = shift;
32 30 my $self = shift;
33 30 my $val = shift;
34 30 my @args = @_;
35  
36 30 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
37 30 $self->$orig($val => @args);
38 4 ▶ } catch {
Subroutine __ANON__: called CC=9 SCAR=23.8
39 4 my $error = $_;
40 4 ▶ if ($error =~ /does not pass the type constraint/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /does not pass the type constraint/) { } 4 0 4
41 4 my $action = $self->on_typeconstraint_failure;
42  
43 4 ▶ if ($action eq 'error') {
Branch: 3 branches
BranchTrueFalseTotal
if ($action eq 'error') { } 1 3 4
elsif ($action eq 'warning') { } 1 2 3
elsif ($action eq 'default' or $action eq 'default_no_warning') { } 2 0 2
44 # Just die like Moose does by default
45 1 die $error;
46 } elsif ($action eq 'warning') {
47 # Warn but keep the current value.
48 1 warn $error;
49 1 return $val;
50 ▶ } elsif ($action eq 'default' or
Condition66%2/3
$action eq "default" or $action eq "default_no_warning"
l!l&&r!l&&!r
110
MC/DC0%0/2
$action eq "default" or $action eq "default_no_warning"
$action eq "default" $action eq "default_no_warning"
Truth table66%2/3
A or B
A= $action eq "default"B= $action eq "default_no_warning"
ABresult
1X1
011
000
51 $action eq 'default_no_warning') {
52 2 ▶ warn $error unless $action eq 'default_no_warning';
Branch: 1 branch
BranchTrueFalseTotal
unless $action eq "default_no_warning" 1 1 2
53 2 ▶ if ($self->has_default) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_default) { } 2 0 2
54 2 my $default = $self->default;
55 2 ▶ return ref $default eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
ref $default eq 'CODE' ? : 2 0 2
56 # If it's e.g. sub { [] }
57 ? $default->()
58 # It's just a normal SV, e.g. "12345"
59 : $default;
60 } else {
61 0 confess(
62 "Attribute ("
63 . $self->name
64 . ") does not have a default value to fall back to"
65 );
66 }
67 } else {
68 0 die "PANIC: Unknown action <$action>";
69 }
70  
71 0 return $val;
72 } else {
73 0 die $error;
74 }
75 30 };
76 2 };
77  
78 package Moose::Meta::Attribute::Custom::Trait::TypeConstraint::CustomizeFatal;
79 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
80 2 $Moose::Meta::Attribute::Custom::Trait::TypeConstraint::CustomizeFatal::AUTHORITY = 'cpan:AVAR';
81 }
82 {
83 2 $Moose::Meta::Attribute::Custom::Trait::TypeConstraint::CustomizeFatal::VERSION = '0.03';
84 }
85 1 ▶sub register_implementation { 'MooseX::Attribute::TypeConstraint::CustomizeFatal' }
Subroutine register_implementation: called CC=1 SCAR=0.0
86  
87 2 1;
88  
89 __END__
↑ Summary