| 1 | package FFI::Build::File::Base; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 15 | ▶ | 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
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | |||||||||||||||||||||||
| 13 | # ABSTRACT: Base class for File::Build files | ||||||||||||||||||||||
| 14 | 15 | our $VERSION = '2.12'; # VERSION | |||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | sub new | ||||||||||||||||||||||
| 18 | 243 | ▶ | { | ||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||
| 19 | 243 | my($class, $content, %config) = @_; | |||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | 243 | ▶ | my $base = $config{base} || 'ffi_build_'; | ||||||||||||||||||||
|
Condition50%1/2
$config{'base'} || 'ffi_build_'
MC/DC0%0/1
$config{'base'} || 'ffi_build_'
$config{'base'}
Truth table50%1/2
A
A= $config{'base'}
| |||||||||||||||||||||||
| 22 | 243 | my $dir = $config{dir}; | |||||||||||||||||||||
| 23 | 243 | my $build = $config{build}; | |||||||||||||||||||||
| 24 | 243 | ▶ | my $platform = $config{platform} || FFI::Build::Platform->new; | ||||||||||||||||||||
|
Condition66%2/3
$config{'platform'} || 'FFI::Build::Platform'->new
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
| |||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | 243 | my $self = bless { | |||||||||||||||||||||
| 27 | platform => $platform, | ||||||||||||||||||||||
| 28 | build => $build, | ||||||||||||||||||||||
| 29 | }, $class; | ||||||||||||||||||||||
| 30 | |||||||||||||||||||||||
| 31 | 243 | ▶ | if(!defined $content) | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||
| 33 | 1 | Carp::croak("content is required"); | |||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||
| 35 | elsif(ref($content) eq 'ARRAY') | ||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||
| 37 | 113 | $self->{path} = File::Spec->catfile(@$content); | |||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||
| 39 | elsif(ref($content) eq 'SCALAR') | ||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||
| 41 | 19 | my %args; | |||||||||||||||||||||
| 42 | 19 | $args{TEMPLATE} = "${base}XXXXXX"; | |||||||||||||||||||||
| 43 | 19 | ▶ | $args{DIR} = $dir if $dir; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 44 | 19 | $args{SUFFIX} = $self->default_suffix; | |||||||||||||||||||||
| 45 | 19 | $args{UNLINK} = 0; | |||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | 19 | my $fh = $self->{fh} = FFI::Temp->new(%args); | |||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | 19 | binmode( $fh, $self->default_encoding ); | |||||||||||||||||||||
| 50 | 19 | print $fh $$content; | |||||||||||||||||||||
| 51 | 19 | close $fh; | |||||||||||||||||||||
| 52 | |||||||||||||||||||||||
| 53 | 19 | $self->{path} = $fh->filename; | |||||||||||||||||||||
| 54 | 19 | $self->{temp} = 1; | |||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||
| 56 | elsif(ref($content) eq '') | ||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||
| 58 | 110 | $self->{path} = $content; | |||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||
| 60 | |||||||||||||||||||||||
| 61 | 242 | ▶ | if($self->platform->osname eq 'MSWin32') | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||
| 63 | 0 | $self->{native} = File::Spec->catfile($self->{path}); | |||||||||||||||||||||
| 64 | 0 | $self->{path} =~ s{\\}{/}g; | |||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||
| 66 | |||||||||||||||||||||||
| 67 | 242 | $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 | 597 | ▶ | sub path { shift->{path} } | ||||||||||||||||||||
|
Subroutine
path: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 77 | 71 | ▶ | sub basename { File::Basename::basename shift->{path} } | ||||||||||||||||||||
|
Subroutine
basename: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 78 | 173 | ▶ | 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 | 654 | ▶ | sub platform { shift->{platform} } | ||||||||||||||||||||
|
Subroutine
platform: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 81 | 668 | ▶ | sub build { shift->{build} } | ||||||||||||||||||||
|
Subroutine
build: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | 2 | ▶ | sub native { | ||||||||||||||||||||
|
Subroutine
native: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||
| 85 | 2 | my($self) = @_; | |||||||||||||||||||||
| 86 | $self->platform->osname eq 'MSWin32' | ||||||||||||||||||||||
| 87 | ? $self->{native} | ||||||||||||||||||||||
| 88 | 2 | ▶ | : $self->{path}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | sub slurp | ||||||||||||||||||||||
| 93 | 4 | ▶ | { | ||||||||||||||||||||
|
Subroutine
slurp: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||
| 94 | 4 | my($self) = @_; | |||||||||||||||||||||
| 95 | 4 | my $fh; | |||||||||||||||||||||
| 96 | 0 | ▶ | open($fh, '<', $self->path) || Carp::croak "Error opening @{[ $self->path ]} for read $!"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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 | 1 | ▶ | { | ||||||||||||||||||||
|
Subroutine
keep: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 106 | 1 | delete shift->{temp}; | |||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | |||||||||||||||||||||||
| 110 | sub build_item | ||||||||||||||||||||||
| 111 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
build_item: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 112 | 0 | Carp::croak("Not implemented!"); | |||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | |||||||||||||||||||||||
| 116 | sub needs_rebuild | ||||||||||||||||||||||
| 117 | 3 | ▶ | { | ||||||||||||||||||||
|
Subroutine
needs_rebuild: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||||||||||||
| 118 | 3 | my($self, @source) = @_; | |||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 127 | 3 | ▶ | return 1 if $source_time > $target_time; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||
| 129 | 0 | return 0; | |||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||
| 131 | |||||||||||||||||||||||
| 132 | |||||||||||||||||||||||
| 133 | sub ld | ||||||||||||||||||||||
| 134 | 116 | ▶ | { | ||||||||||||||||||||
|
Subroutine
ld: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 135 | 116 | return undef; | |||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||
| 137 | |||||||||||||||||||||||
| 138 | sub DESTROY | ||||||||||||||||||||||
| 139 | 94 | ▶ | { | ||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
| |||||||||||||||||||||||
| 140 | 94 | my($self) = @_; | |||||||||||||||||||||
| 141 | |||||||||||||||||||||||
| 142 | 94 | ▶ | if($self->{temp}) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 143 | { | ||||||||||||||||||||||
| 144 | 10 | unlink($self->path); | |||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||
| 147 | |||||||||||||||||||||||
| 148 | 15 | 1; | |||||||||||||||||||||
| 149 | |||||||||||||||||||||||
| 150 | __END__ | ||||||||||||||||||||||