line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Module::Build::Pluggable; |
2
|
10
|
|
|
10
|
|
266845
|
use strict; |
|
10
|
|
|
|
|
33
|
|
|
10
|
|
|
|
|
440
|
|
3
|
10
|
|
|
10
|
|
53
|
use warnings; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
276
|
|
4
|
10
|
|
|
10
|
|
43
|
use utf8; |
|
10
|
|
|
|
|
30
|
|
|
10
|
|
|
|
|
77
|
|
5
|
|
|
|
|
|
|
|
6
|
10
|
|
|
10
|
|
13477
|
use File::Temp qw/tempdir/; |
|
10
|
|
|
|
|
295300
|
|
|
10
|
|
|
|
|
808
|
|
7
|
10
|
|
|
10
|
|
87
|
use Cwd; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
634
|
|
8
|
10
|
|
|
10
|
|
10232
|
use Test::SharedFork; |
|
10
|
|
|
|
|
194192
|
|
|
10
|
|
|
|
|
146
|
|
9
|
10
|
|
|
10
|
|
1693
|
use File::Basename (); |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
173
|
|
10
|
10
|
|
|
10
|
|
57
|
use File::Path (); |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
9017
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
11
|
|
|
11
|
1
|
40246
|
my $class = shift; |
14
|
11
|
50
|
|
|
|
70
|
my %args = @_==1 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
15
|
11
|
|
|
|
|
97
|
my $self = bless { |
16
|
|
|
|
|
|
|
files => [], |
17
|
|
|
|
|
|
|
cleanup => 1, |
18
|
|
|
|
|
|
|
%args |
19
|
|
|
|
|
|
|
}, $class; |
20
|
11
|
|
|
|
|
165
|
$self->{origcwd} = Cwd::getcwd(); |
21
|
11
|
|
|
|
|
104
|
$self->{dir} = tempdir(CLEANUP => $self->{cleanup}); |
22
|
11
|
|
|
|
|
6521
|
$self->{libdir} = tempdir(CLEANUP => $self->{cleanup}); |
23
|
11
|
|
|
|
|
4303
|
unshift @INC, $self->{libdir}; |
24
|
11
|
|
|
|
|
186
|
chdir $self->{dir}; |
25
|
11
|
|
|
|
|
49
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub DESTROY { |
29
|
11
|
|
|
11
|
|
23024
|
my $self = shift; |
30
|
11
|
|
|
|
|
1366
|
chdir($self->{origcwd}); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub write_plugin { |
34
|
13
|
|
|
13
|
1
|
101
|
my ($self, $package, $content) = @_; |
35
|
|
|
|
|
|
|
|
36
|
13
|
|
|
|
|
25
|
my $ofile = do { |
37
|
13
|
|
|
|
|
50
|
my $path = $package; |
38
|
13
|
|
|
|
|
78
|
$path =~ s!::!/!g; |
39
|
13
|
|
|
|
|
29
|
$path .= ".pm"; |
40
|
13
|
|
|
|
|
178
|
File::Spec->catfile($self->{libdir}, $path); |
41
|
|
|
|
|
|
|
}; |
42
|
13
|
|
|
|
|
6110
|
File::Path::mkpath(File::Basename::dirname($ofile)); |
43
|
13
|
50
|
|
|
|
1088
|
open my $fh, '>', $ofile or die "Cannot open $ofile, $!"; |
44
|
13
|
|
|
|
|
29
|
print {$fh} $content; |
|
13
|
|
|
|
|
115
|
|
45
|
13
|
|
|
|
|
590
|
close $fh; |
46
|
|
|
|
|
|
|
|
47
|
13
|
|
|
|
|
27
|
push @{$self->{files}}, $ofile; |
|
13
|
|
|
|
|
99
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub write_file { |
51
|
22
|
|
|
22
|
1
|
139
|
my ($self, $fname, $content) = @_; |
52
|
|
|
|
|
|
|
|
53
|
22
|
50
|
|
|
|
612
|
if (my $dir = File::Basename::dirname($fname)) { |
54
|
22
|
|
|
|
|
621
|
File::Path::mkpath($dir); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
22
|
50
|
|
|
|
1400
|
open my $fh, '>', $fname or die "Cannot open $fname: $!"; |
58
|
22
|
|
|
|
|
116
|
print $fh $content; |
59
|
22
|
|
|
|
|
724
|
close $fh; |
60
|
|
|
|
|
|
|
|
61
|
22
|
|
|
|
|
36
|
push @{$self->{files}}, $fname; |
|
22
|
|
|
|
|
124
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub write_manifest { |
65
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
0
|
open my $fh, '>', 'MANIFEST' or die "Cannot open MANIFEST: $!"; |
68
|
0
|
|
|
|
|
0
|
for (@{$self->{files}}) { |
|
0
|
|
|
|
|
0
|
|
69
|
0
|
|
|
|
|
0
|
print $fh $_ . "\n"; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
0
|
close $fh; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub read_file { |
75
|
6
|
|
|
6
|
0
|
158
|
my ($self, $fname) = @_; |
76
|
6
|
50
|
|
|
|
630
|
open my $fh, '<', $fname or die "Cannot open $fname in @{[ Cwd::getcwd() ]}: $!"; |
|
0
|
|
|
|
|
0
|
|
77
|
6
|
|
|
|
|
125
|
local $/; |
78
|
6
|
|
|
|
|
419
|
scalar(<$fh>); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub run_build_script { |
82
|
0
|
|
|
0
|
1
|
0
|
my ($self, @args) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
0
|
my $pid = fork(); |
85
|
0
|
0
|
|
|
|
0
|
die "fork failed: $!" unless defined $pid; |
86
|
0
|
0
|
|
|
|
0
|
if ($pid) { |
87
|
0
|
|
|
|
|
0
|
waitpid $pid, 0; |
88
|
|
|
|
|
|
|
} else { |
89
|
0
|
|
|
|
|
0
|
local @ARGV = (@args); |
90
|
0
|
|
|
|
|
0
|
do 'Build'; |
91
|
0
|
0
|
|
|
|
0
|
::ok(!$@) or ::diag $@; |
92
|
0
|
|
|
|
|
0
|
exit 0; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub run_build_pl { |
97
|
11
|
|
|
11
|
1
|
82
|
my ($self, @args) = @_; |
98
|
|
|
|
|
|
|
|
99
|
11
|
|
|
|
|
19557
|
my $pid = fork(); |
100
|
11
|
50
|
|
|
|
759
|
die "fork failed: $!" unless defined $pid; |
101
|
11
|
100
|
|
|
|
451
|
if ($pid) { |
102
|
6
|
|
|
|
|
6075447
|
waitpid $pid, 0; |
103
|
|
|
|
|
|
|
} else { |
104
|
5
|
|
|
|
|
7022
|
local @ARGV = @args; |
105
|
5
|
|
|
|
|
18333
|
do 'Build.PL'; |
106
|
5
|
50
|
|
|
|
328175
|
::ok(-f 'Build', 'Created Build file') or ::diag $@; |
107
|
5
|
|
|
|
|
12292
|
exit 0; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
__END__ |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 NAME |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Test::Module::Build::Pluggable - Test your plugin |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SYNOPSIS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $test = Test::Module::Build::Pluggable->new(); |
121
|
|
|
|
|
|
|
$test->write_file('Build.PL', <<'...'); |
122
|
|
|
|
|
|
|
... |
123
|
|
|
|
|
|
|
$test->run_build_pl(); |
124
|
|
|
|
|
|
|
$test->run_build_script(); |
125
|
|
|
|
|
|
|
# test... |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 METHODS |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=over 4 |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item C<< my $test = Test::Module::Build::Pluggable->new() >> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item C<< $test->write_file($filename, $src); >> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item C<< $test->write_plugin($package, $src); >> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item C<< $test->write_manifest(); >> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Write manifest from file list. The file list means list of file name added by C<< $test->write_file >> and C<< $test->write_plugin >> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item C<< $test->run_build_pl(); >> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item C<< $test->run_build_script(); >> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=back |
146
|
|
|
|
|
|
|
|