lib/FFI/Build/File/Base.pm

filter: Statementstmt 91.1% 82 / 90 Branchbran 70.8% 17 / 24 Conditioncond 60.0% 3 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 85.1% 23 / 27 Podpod 100% 16 / 16 totaltotal 85.4% 141 / 165 CC 16 SCAR 12.5
CC
16
Cov
86%
new
9.2
needs_rebuild
5.6
native
2.1
CRAP 3.5
« lib/FFI/Temp.pm ↑ Summary blib/lib/FFI/Build/PluginData.pm »
1 package FFI::Build::File::Base;
2  
3 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use FFI::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use File::Basename ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use FFI::Build::Platform;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use FFI::Build::PluginData;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use overload '""' => sub { $_[0]->path }, bool => sub { 1 }, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
12  
13 # ABSTRACT: Base class for File::Build files
14 15 our $VERSION = '2.11'; # VERSION
15  
16  
17 sub new
18 {
19 232 ▶ my($class, $content, %config) = @_;
Subroutine new: called CC=9 SCAR=22.2
Pod documented
20  
21 232 ▶ my $base = $config{base} || 'ffi_build_';
Condition50%1/2
$config{'base'} || 'ffi_build_'
l!l
0232
MC/DC0%0/1
$config{'base'} || 'ffi_build_'
$config{'base'}
Truth table50%1/2
A
A= $config{'base'}
Aresult
11
00
22 232 my $dir = $config{dir};
23 232 my $build = $config{build};
24 232 ▶ my $platform = $config{platform} || FFI::Build::Platform->new;
Condition66%2/3
$config{'platform'} || 'FFI::Build::Platform'->new
l!l&&r!l&&!r
207250
MC/DC0%0/2
$config{'platform'} || 'FFI::Build::Platform'->new
$config{'platform'} 'FFI::Build::Platform'->new
Truth table66%2/3
A || B
A= $config{'platform'}B= 'FFI::Build::Platform'->new
ABresult
1X1
011
000
25  
26 232 my $self = bless {
27 platform => $platform,
28 build => $build,
29 }, $class;
30  
31 232 ▶ if(!defined $content)
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $content) { } 1 231 232
elsif (ref $content eq 'ARRAY') { } 105 126 231
elsif (ref $content eq 'SCALAR') { } 18 108 126
elsif (ref $content eq '') { } 108 0 108
32 {
33 1 Carp::croak("content is required");
34 }
35 elsif(ref($content) eq 'ARRAY')
36 {
37 105 $self->{path} = File::Spec->catfile(@$content);
38 }
39 elsif(ref($content) eq 'SCALAR')
40 {
41 18 my %args;
42 18 $args{TEMPLATE} = "${base}XXXXXX";
43 18 ▶ $args{DIR} = $dir if $dir;
Branch: 1 branch
BranchTrueFalseTotal
if $dir 8 10 18
44 18 $args{SUFFIX} = $self->default_suffix;
45 18 $args{UNLINK} = 0;
46  
47 18 my $fh = $self->{fh} = FFI::Temp->new(%args);
48  
49 18 binmode( $fh, $self->default_encoding );
50 18 print $fh $$content;
51 18 close $fh;
52  
53 18 $self->{path} = $fh->filename;
54 18 $self->{temp} = 1;
55 }
56 elsif(ref($content) eq '')
57 {
58 108 $self->{path} = $content;
59 }
60  
61 231 ▶ if($self->platform->osname eq 'MSWin32')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->platform->osname eq "MSWin32") 0 231 231
62 {
63 0 $self->{native} = File::Spec->catfile($self->{path});
64 0 $self->{path} =~ s{\\}{/}g;
65 }
66  
67 231 $self;
68 }
69  
70  
71 0 ▶sub default_suffix { die "must define a default extension in subclass" }
Subroutine default_suffix: not called CC=1 SCAR=6.9
Pod documented
72 0 ▶sub default_encoding { die "must define an encoding" }
Subroutine default_encoding: not called CC=1 SCAR=6.9
Pod documented
73 0 ▶sub accept_suffix { () }
Subroutine accept_suffix: not called CC=1 SCAR=6.9
Pod documented
74  
75  
76 562 ▶sub path { shift->{path} }
Subroutine path: called CC=1 SCAR=0.0
Pod documented
77 68 ▶sub basename { File::Basename::basename shift->{path} }
Subroutine basename: called CC=1 SCAR=0.0
Pod documented
78 163 ▶sub dirname { File::Basename::dirname shift->{path} }
Subroutine dirname: called CC=1 SCAR=0.0
Pod documented
79 3 ▶sub is_temp { shift->{temp} }
Subroutine is_temp: called CC=1 SCAR=0.0
Pod documented
80 617 ▶sub platform { shift->{platform} }
Subroutine platform: called CC=1 SCAR=0.0
Pod documented
81 640 ▶sub build { shift->{build} }
Subroutine build: called CC=1 SCAR=0.0
Pod documented
82  
83  
84 sub native {
85 2 ▶ my($self) = @_;
Subroutine native: called CC=2 SCAR=7.2
Pod documented
86 $self->platform->osname eq 'MSWin32'
87 ? $self->{native}
88 2 ▶ : $self->{path};
Branch: 1 branch
BranchTrueFalseTotal
$self->platform->osname eq 'MSWin32' ? : 0 2 2
89 }
90  
91  
92 sub slurp
93 {
94 4 ▶ my($self) = @_;
Subroutine slurp: called CC=2 SCAR=7.0
Pod documented
95 4 my $fh;
96 4 ▶ open($fh, '<', $self->path) || Carp::croak "Error opening @{[ $self->path ]} for read $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $self->path or Carp::croak("Error opening @{[$self->path];} for read $!") 0 4 4
97 4 binmode($fh, $self->default_encoding);
98 4 my $content = do { local $/; <$fh> };
99 4 close $fh;
100 4 $content;
101 }
102  
103  
104 sub keep
105 {
106 1 ▶ delete shift->{temp};
Subroutine keep: called CC=1 SCAR=0.0
Pod documented
107 }
108  
109  
110 sub build_item
111 {
112 0 ▶ Carp::croak("Not implemented!");
Subroutine build_item: not called CC=1 SCAR=6.9
Pod documented
113 }
114  
115  
116 sub needs_rebuild
117 {
118 3 ▶ my($self, @source) = @_;
Subroutine needs_rebuild: called CC=5 SCAR=17.2
Pod documented
119 # if the target doesn't exist, then we definitely
120 # need a rebuild.
121 3 ▶ return 1 unless -f $self->path;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $self->path 0 3 3
122 3 my $target_time = [stat $self->path]->[9];
123 3 foreach my $source (@source)
124 {
125 3 my $source_time = [stat "$source"]->[9];
126 3 ▶ return 1 if ! defined $source_time;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $source_time 0 3 3
127 3 ▶ return 1 if $source_time > $target_time;
Branch: 1 branch
BranchTrueFalseTotal
if $source_time > $target_time 3 0 3
128 }
129 0 return 0;
130 }
131  
132  
133 sub ld
134 {
135 114 ▶ return undef;
Subroutine ld: called CC=1 SCAR=0.0
Pod documented
136 }
137  
138 sub DESTROY
139 {
140 86 ▶ my($self) = @_;
Subroutine DESTROY: called CC=2 SCAR=6.9
141  
142 86 ▶ if($self->{temp})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"temp"}) 9 77 86
143 {
144 9 unlink($self->path);
145 }
146 }
147  
148 15 1;
149  
150 __END__
« lib/FFI/Temp.pm ↑ Summary blib/lib/FFI/Build/PluginData.pm »