Courriel/Types/Internal.pm

filter: Statementstmt 84.8% 56 / 66 Branchbran 50.0% 7 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 63.1% 12 / 19 Podpod n/a totaltotal 73.0% 76 / 104 CC 10 SCAR 11.0
CC
10
Cov
77%
__ANON__
6.5
__ANON__
6.0
__ANON__
3.6
CRAP 3.0
« Courriel/Header/Disposition.pm ↑ Summary Courriel/Part/Single.pm »
1 package Courriel::Types::Internal;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 our $VERSION = '0.49';
8  
9 10 ▶use List::AllUtils qw( all );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 10 ▶use MooseX::Types -declare => [
Subroutine BEGIN: called CC=1 SCAR=0.0
13 qw(
14 Body
15 EmailAddressStr
16 HeaderArray
17 Headers
18 Part
19 Printable
20 Streamable
21 StringRef
22 )
23 10 ];
24 10 ▶use MooseX::Types::Common::String qw( NonEmptyStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 use MooseX::Types::Moose
26 10 ▶ qw( ArrayRef CodeRef FileHandle HashRef Object ScalarRef Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 #<<<
29 10 subtype Body,
30 as role_type('Courriel::Role::Body');
31  
32 10 subtype Headers,
33 as class_type('Courriel::Headers');
34  
35 10 subtype EmailAddressStr,
36 as NonEmptyStr;
37  
38 coerce EmailAddressStr,
39 from class_type('Email::Address::XS'),
40 0 ▶ via { $_->format };
Subroutine __ANON__: not called CC=1 SCAR=1.2
41  
42 159 ▶my $_check_header_array = sub {
Subroutine __ANON__: called CC=6 SCAR=18.7
43 159 ▶ return 0 unless @{$_} % 2 == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_;} % 2 == 0 0 159 159
44  
45 159 my ( @even, @odd );
46 159 for my $i ( 0 .. $#{$_} ) {
47 4182 ▶ if ( $i % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i % 2) { } 2091 2091 4182
48 2091 push @odd, $i;
49 }
50 else {
51 2091 push @even, $i;
52 }
53 }
54  
55 ## no critic (ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions)
56 159 ▶ return 0 unless all { defined $_ && length $_ && !ref $_ } @{$_}[@even];
Subroutine __ANON__: called CC=3 SCAR=12.7
Branch: 2 branches
BranchTrueFalseTotal
unless &all(sub { defined $_ and length $_ and not ref $_; } , @{$_;}[@even]) 0 159 159
defined $_ and length $_ and not ref $_ 2091 0 2091
Condition33%1/3
defined $_ and length $_
!ll&&!rl&&r
002091
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table33%1/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
57 ## use critic;
58 return 0
59 159 ▶ unless all { blessed($_) && $_->isa('Courriel::Header') } @{$_}[@odd];
Subroutine __ANON__: called CC=2 SCAR=7.4
Branch: 2 branches
BranchTrueFalseTotal
unless &all(sub { builtin::blessed($_) and $_->isa("Courriel::Header"); } , @{$_;}[@odd]) 0 159 159
builtin::blessed($_) and $_->isa("Courriel::Header") 2091 0 2091
60  
61 159 return 1;
62 10 };
63  
64 subtype HeaderArray,
65 as ArrayRef,
66 # prototype wants an actual block, not a ref to a sub
67 &where($_check_header_array),
68 0 ▶ message { 'The array reference must contain an even number of elements' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
69  
70 10 subtype Part,
71 as role_type('Courriel::Role::Part');
72  
73 subtype Printable,
74 as Object,
75 0 ▶ where { $_->can('print') };
Subroutine __ANON__: not called CC=1 SCAR=1.2
76  
77 10 subtype Streamable,
78 as CodeRef;
79  
80 coerce Streamable,
81 from FileHandle,
82 0 ▶ via sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 0 my $fh = $_;
84 0 ▶ return sub { print {$fh} @_ or die $! };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
print {$fh;} @_ or die $! 0 0 0
85 10 };
86  
87 coerce Streamable,
88 from Printable,
89 0 ▶ via sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 0 my $obj = $_;
91 0 ▶ return sub { $obj->print(@_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 10 };
93  
94 10 subtype StringRef,
95 as ScalarRef[Str];
96  
97 coerce StringRef,
98 from Str,
99 67 ▶ via { my $str = $_; \$str };
Subroutine __ANON__: called CC=1 SCAR=0.0
100 #>>>
101 10 1;
« Courriel/Header/Disposition.pm ↑ Summary Courriel/Part/Single.pm »