line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FFI::Build::File::Base; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
66673
|
use strict; |
|
10
|
|
|
|
|
34
|
|
|
10
|
|
|
|
|
273
|
|
4
|
10
|
|
|
10
|
|
49
|
use warnings; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
209
|
|
5
|
10
|
|
|
10
|
|
151
|
use 5.008001; |
|
10
|
|
|
|
|
32
|
|
6
|
10
|
|
|
10
|
|
56
|
use Carp (); |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
227
|
|
7
|
10
|
|
|
10
|
|
5764
|
use File::Temp (); |
|
10
|
|
|
|
|
163703
|
|
|
10
|
|
|
|
|
249
|
|
8
|
10
|
|
|
10
|
|
71
|
use File::Basename (); |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
168
|
|
9
|
10
|
|
|
10
|
|
3543
|
use FFI::Build::Platform; |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
565
|
|
10
|
10
|
|
|
10
|
|
84
|
use overload '""' => sub { $_[0]->path }; |
|
10
|
|
|
57
|
|
24
|
|
|
10
|
|
|
|
|
86
|
|
|
57
|
|
|
|
|
2552
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Base class for File::Build files |
13
|
|
|
|
|
|
|
our $VERSION = '0.12'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new |
17
|
|
|
|
|
|
|
{ |
18
|
75
|
|
|
75
|
1
|
140063
|
my($class, $content, %config) = @_; |
19
|
|
|
|
|
|
|
|
20
|
75
|
|
50
|
|
|
487
|
my $base = $config{base} || 'ffi_build_'; |
21
|
75
|
|
|
|
|
226
|
my $dir = $config{dir}; |
22
|
75
|
|
|
|
|
198
|
my $build = $config{build}; |
23
|
75
|
|
66
|
|
|
420
|
my $platform = $config{platform} || FFI::Build::Platform->new; |
24
|
|
|
|
|
|
|
|
25
|
75
|
|
|
|
|
402
|
my $self = bless { |
26
|
|
|
|
|
|
|
platform => $platform, |
27
|
|
|
|
|
|
|
build => $build, |
28
|
|
|
|
|
|
|
}, $class; |
29
|
|
|
|
|
|
|
|
30
|
75
|
100
|
|
|
|
464
|
if(!defined $content) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
31
|
|
|
|
|
|
|
{ |
32
|
1
|
|
|
|
|
200
|
Carp::croak("content is required"); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
elsif(ref($content) eq 'ARRAY') |
35
|
|
|
|
|
|
|
{ |
36
|
37
|
|
|
|
|
1261
|
$self->{path} = File::Spec->catfile(@$content); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif(ref($content) eq 'SCALAR') |
39
|
|
|
|
|
|
|
{ |
40
|
7
|
|
|
|
|
17
|
my @args; |
41
|
7
|
|
|
|
|
24
|
push @args, "${base}XXXXXX"; |
42
|
7
|
50
|
|
|
|
24
|
push @args, DIR => $dir if $dir; |
43
|
7
|
|
|
|
|
66
|
push @args, SUFFIX => $self->default_suffix; |
44
|
|
|
|
|
|
|
|
45
|
7
|
|
|
|
|
46
|
my($fh, $filename) = File::Temp::tempfile(@args); |
46
|
|
|
|
|
|
|
|
47
|
7
|
|
|
|
|
3099
|
binmode( $fh, $self->default_encoding ); |
48
|
7
|
|
|
|
|
99
|
print $fh $$content; |
49
|
7
|
|
|
|
|
269
|
close $fh; |
50
|
|
|
|
|
|
|
|
51
|
7
|
|
|
|
|
103
|
$self->{path} = $filename; |
52
|
7
|
|
|
|
|
44
|
$self->{temp} = 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif(ref($content) eq '') |
55
|
|
|
|
|
|
|
{ |
56
|
30
|
|
|
|
|
168
|
$self->{path} = $content; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
74
|
50
|
|
|
|
343
|
if($self->platform->osname eq 'MSWin32') |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
|
|
0
|
$self->{native} = File::Spec->catfile($self->{path}); |
62
|
0
|
|
|
|
|
0
|
$self->{path} =~ s{\\}{/}g; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
74
|
|
|
|
|
438
|
$self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
0
|
1
|
0
|
sub default_suffix { die "must define a default extension in subclass" } |
70
|
0
|
|
|
0
|
1
|
0
|
sub default_encoding { die "must define an encoding" } |
71
|
0
|
|
|
0
|
1
|
0
|
sub accept_suffix { () } |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
178
|
|
|
178
|
1
|
3072
|
sub path { shift->{path} } |
75
|
20
|
|
|
20
|
1
|
2661
|
sub basename { File::Basename::basename shift->{path} } |
76
|
51
|
|
|
51
|
1
|
6405
|
sub dirname { File::Basename::dirname shift->{path} } |
77
|
3
|
|
|
3
|
1
|
16
|
sub is_temp { shift->{temp} } |
78
|
174
|
|
|
174
|
1
|
1002
|
sub platform { shift->{platform} } |
79
|
90
|
|
|
90
|
1
|
1110
|
sub build { shift->{build} } |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub native { |
83
|
2
|
|
|
2
|
1
|
618
|
my($self) = @_; |
84
|
|
|
|
|
|
|
$self->platform->osname eq 'MSWin32' |
85
|
|
|
|
|
|
|
? $self->{native} |
86
|
2
|
50
|
|
|
|
6
|
: $self->{path}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub slurp |
91
|
|
|
|
|
|
|
{ |
92
|
4
|
|
|
4
|
1
|
833
|
my($self) = @_; |
93
|
4
|
|
|
|
|
5
|
my $fh; |
94
|
4
|
50
|
|
|
|
21
|
open($fh, '<', $self->path) || Carp::croak "Error opening @{[ $self->path ]} for read $!"; |
|
0
|
|
|
|
|
0
|
|
95
|
4
|
|
|
|
|
33
|
binmode($fh, $self->default_encoding); |
96
|
4
|
|
|
|
|
9
|
my $content = do { local $/; <$fh> }; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
119
|
|
97
|
4
|
|
|
|
|
37
|
close $fh; |
98
|
4
|
|
|
|
|
34
|
$content; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub keep |
103
|
|
|
|
|
|
|
{ |
104
|
1
|
|
|
1
|
1
|
11
|
delete shift->{temp}; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub build_item |
109
|
|
|
|
|
|
|
{ |
110
|
0
|
|
|
0
|
1
|
0
|
Carp::croak("Not implemented!"); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub needs_rebuild |
115
|
|
|
|
|
|
|
{ |
116
|
0
|
|
|
0
|
1
|
0
|
my($self, @source) = @_; |
117
|
|
|
|
|
|
|
# if the target doesn't exist, then we definitely |
118
|
|
|
|
|
|
|
# need a rebuild. |
119
|
0
|
0
|
|
|
|
0
|
return 1 unless -f $self->path; |
120
|
0
|
|
|
|
|
0
|
my $target_time = [stat $self->path]->[9]; |
121
|
0
|
|
|
|
|
0
|
foreach my $source (@source) |
122
|
|
|
|
|
|
|
{ |
123
|
0
|
|
|
|
|
0
|
my $source_time = [stat "$source"]->[9]; |
124
|
0
|
0
|
|
|
|
0
|
return 1 if $source_time > $target_time; |
125
|
|
|
|
|
|
|
} |
126
|
0
|
|
|
|
|
0
|
return 0; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub ld |
131
|
|
|
|
|
|
|
{ |
132
|
22
|
|
|
22
|
1
|
116
|
return undef; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub DESTROY |
136
|
|
|
|
|
|
|
{ |
137
|
37
|
|
|
37
|
|
12579
|
my($self) = @_; |
138
|
|
|
|
|
|
|
|
139
|
37
|
100
|
|
|
|
910
|
if($self->{temp}) |
140
|
|
|
|
|
|
|
{ |
141
|
6
|
|
|
|
|
93
|
unlink($self->path); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |