Builder/Role/File.pm

filter: Statementstmt 83.0% 49 / 59 Branchbran 55.0% 11 / 20 Conditioncond 53.3% 8 / 15 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 4 totaltotal 68.9% 82 / 119 CC 17 SCAR 24.7
CC
17
Cov
72%
compare
42.0
filehandle
5.5
filecontent
4.0
CRAP 11.8
« Builder.pm ↑ Summary Builder/Address.pm »
1 # ============================================================================
2 package Mail::Builder::Role::File;
3 # ============================================================================
4  
5 8 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use Path::Class qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use IO::File qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 our $VERSION = $Mail::Builder::VERSION;
12  
13 has 'file' => (
14 is => 'rw',
15 isa => 'Mail::Builder::Type::Content | Mail::Builder::Type::File | Mail::Builder::Type::Fh',
16 required => 1,
17 coerce => 1,
18 10 ▶ trigger => sub { shift->clear_cache },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 8 );
20  
21 8 has 'cache' => (
22 is => 'rw',
23 predicate => 'has_cache',
24 clearer => 'clear_cache',
25 );
26  
27 8 our %MAGIC_STRINGS = (
28 'image/gif' => _build_magic_string(0x47,0x49,0x46,0x38,0x39,0x61),
29 'image/jpeg'=> _build_magic_string(0xFF,0xD8),
30 'image/png' => _build_magic_string(0x89,0x50,0x4E,0x47,0x0D,0x0A),
31 );
32  
33 24 ▶sub _build_magic_string {
Subroutine _build_magic_string: called CC=1 SCAR=0.0
34 24 my (@chars) = @_;
35 24 return join ('',map { chr($_) } @chars);
36 }
37  
38 3 ▶sub _check_magic_string {
Subroutine _check_magic_string: called CC=3 SCAR=11.0
39 3 my ($self,$string) = @_;
40  
41 3 foreach my $type (keys %MAGIC_STRINGS) {
42 return $type
43 7 ▶ if substr($string,0,(length $MAGIC_STRINGS{$type})) eq $MAGIC_STRINGS{$type};
Branch: 1 branch
BranchTrueFalseTotal
if substr($string, 0, length $Mail::Builder::Role::File::MAGIC_STRINGS{$type}) eq $Mail::Builder::Role::File::MAGIC_STRINGS{$type} 1 6 7
44 }
45 2 return;
46 }
47  
48 25 ▶sub filename {
Subroutine filename: called CC=3 SCAR=11.0
Pod undocumented
49 25 my ($self) = @_;
50  
51 25 my $file = $self->file;
52  
53 # Return filename if we know it
54 25 ▶ if (blessed $file
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($file) and $file->isa("Path::Class::File")) 17 8 25
Condition100%3/3
builtin::blessed($file) and $file->isa("Path::Class::File")
!ll&&!rl&&r
2617
MC/DC100%2/2
builtin::blessed($file) and $file->isa("Path::Class::File")
builtin::blessed($file) $file->isa("Path::Class::File")
Truth table100%3/3
A and B
A= builtin::blessed($file)B= $file->isa("Path::Class::File")
ABresult
0X0
100
111
55 && $file->isa('Path::Class::File')) {
56 17 return $file;
57 }
58  
59 # We don't know the filename
60 8 return;
61 }
62  
63 9 ▶sub filehandle {
Subroutine filehandle: called CC=5 SCAR=17.0
Pod undocumented
64 9 my ($self) = @_;
65  
66 9 my $file = $self->file;
67  
68 9 my $file_handle;
69  
70 # Open Path::Class::File
71 9 ▶ if (blessed $file
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($file) and $file->isa('Path::Class::File')) { } 2 7 9
elsif (builtin::blessed($file) and $file->isa('IO::File')) { } 7 0 7
Condition66%2/3
builtin::blessed($file) and $file->isa("Path::Class::File")
!ll&&!rl&&r
072
MC/DC50%1/2
builtin::blessed($file) and $file->isa("Path::Class::File")
builtin::blessed($file) $file->isa("Path::Class::File")
Truth table66%2/3
A and B
A= builtin::blessed($file)B= $file->isa("Path::Class::File")
ABresult
0X0
100
111
72 && $file->isa('Path::Class::File')) {
73 2 $file_handle = $file->openr();
74 # Return filehandle
75 ▶ } elsif (blessed $file
Condition33%1/3
builtin::blessed($file) and $file->isa("IO::File")
!ll&&!rl&&r
007
MC/DC0%0/2
builtin::blessed($file) and $file->isa("IO::File")
builtin::blessed($file) $file->isa("IO::File")
Truth table33%1/3
A and B
A= builtin::blessed($file)B= $file->isa("IO::File")
ABresult
0X0
100
111
76 && $file->isa('IO::File')) {
77 7 $file_handle = $file;
78 # We don't have a filehandle
79 } else {
80 0 return;
81 }
82  
83 9 $file_handle->binmode();
84 9 return $file_handle;
85 }
86  
87 11 ▶sub filecontent {
Subroutine filecontent: called CC=4 SCAR=13.9
Pod undocumented
88 11 my ($self) = @_;
89  
90 11 my $file = $self->file;
91  
92 11 ▶ return $$file
Branch: 1 branch
BranchTrueFalseTotal
if ref $file eq "SCALAR" 2 9 11
93 if ref $file eq 'SCALAR';
94  
95 9 my $filehandle = $self->filehandle;
96  
97 9 my $filecontent = do { local $/; <$filehandle> };
98  
99 9 ▶ if (blessed $file
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($file) and $file->isa('Path::Class::File')) { } 2 7 9
Condition66%2/3
builtin::blessed($file) and $file->isa("Path::Class::File")
!ll&&!rl&&r
072
MC/DC50%1/2
builtin::blessed($file) and $file->isa("Path::Class::File")
builtin::blessed($file) $file->isa("Path::Class::File")
Truth table66%2/3
A and B
A= builtin::blessed($file)B= $file->isa("Path::Class::File")
ABresult
0X0
100
111
100 && $file->isa('Path::Class::File')) {
101 2 $filehandle->close;
102 } else {
103 7 $filehandle->seek(0,0);
104 }
105  
106 9 return $filecontent;
107 }
108  
109  
110 0 ▶sub compare {
Subroutine compare: not called CC=6 SCAR=37.4
Pod undocumented
111 0 my ($self,$compare) = @_;
112  
113 0 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless $compare 0 0 0
114 unless ($compare);
115  
116 0 my $filename_self = $self->filename;
117 0 my $filename_compare = $compare->filename;
118  
119 0 ▶ if (defined $filename_self
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filename_self and defined $filename_compare) 0 0 0
Condition0%0/3
defined $filename_self and defined $filename_compare
!ll&&!rl&&r
000
MC/DC0%0/2
defined $filename_self and defined $filename_compare
defined $filename_self defined $filename_compare
Truth table0%0/3
A and B
A= defined $filename_selfB= defined $filename_compare
ABresult
0X0
100
111
120 && defined $filename_compare) {
121 0 ▶ return ($filename_self eq $filename_compare ? 1:0);
Branch: 1 branch
BranchTrueFalseTotal
$filename_self eq $filename_compare ? : 0 0 0
122 }
123  
124 0 my $filecontent_self = $self->filecontent;
125 0 my $filecontent_compare = $compare->filecontent;
126  
127 0 ▶ return ($filecontent_self eq $filecontent_compare ? 1:0);
Branch: 1 branch
BranchTrueFalseTotal
$filecontent_self eq $filecontent_compare ? : 0 0 0
128 }
129  
130 8 1;
« Builder.pm ↑ Summary Builder/Address.pm »