line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::MyPerl::Rewrite; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1226
|
use Moo; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
15
|
|
4
|
2
|
|
|
2
|
|
537
|
use IO::All; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
15
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with 'App::MyPerl::Role::Script'; |
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
0
|
31
|
sub use_files { qw(modules) } |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has exclude_dev_preamble => (is => 'lazy', builder => sub { |
11
|
1
|
|
|
1
|
|
350
|
join "\n", '# App::MyPerl preamble', @{$_[0]->preamble}, |
|
1
|
|
|
|
|
4
|
|
12
|
|
|
|
|
|
|
}); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has exclude_dev_script_preamble => (is => 'lazy', builder => sub { |
15
|
1
|
|
|
|
|
8
|
join "\n", |
16
|
|
|
|
|
|
|
'# App::MyPerl script preamble', |
17
|
1
|
|
|
1
|
|
393
|
@{$_[0]->_preamble_from_modules(@{$_[0]->script_modules})}; |
|
1
|
|
|
|
|
1
|
|
18
|
|
|
|
|
|
|
}); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub run { |
21
|
0
|
0
|
|
0
|
0
|
0
|
die "myperl-rewrite dir1 dir2 ..." unless @ARGV; |
22
|
0
|
|
|
|
|
0
|
$_[0]->rewrite_dir($_) for @ARGV; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub rewrite_dir { |
26
|
0
|
|
|
0
|
0
|
0
|
my ($self, $dir) = @_; |
27
|
0
|
0
|
|
|
|
0
|
if ($self->_env_value('DEBUG')) { |
28
|
0
|
|
|
|
|
0
|
warn $self->exclude_dev_script_preamble."\n"; |
29
|
0
|
|
|
|
|
0
|
warn $self->exclude_dev_preamble."\n"; |
30
|
|
|
|
|
|
|
} |
31
|
0
|
|
|
|
|
0
|
my @files = grep $_->name =~ /\.pm$|\.t$|^${dir}\/bin\//, |
32
|
|
|
|
|
|
|
io->dir($dir)->all_files(0); |
33
|
0
|
|
|
|
|
0
|
foreach my $file (@files) { |
34
|
0
|
|
|
|
|
0
|
my $data = $file->all; |
35
|
0
|
|
|
|
|
0
|
$file->print($self->rewritten_contents($data)); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub rewritten_contents { |
40
|
2
|
|
|
2
|
0
|
170
|
my ($self, $data) = @_; |
41
|
2
|
|
|
|
|
2
|
my ($shebang, $line) = do { |
42
|
2
|
100
|
|
|
|
9
|
if ($data =~ s/\A(#!.*\n)//) { |
43
|
1
|
|
|
|
|
4
|
($1.$self->exclude_dev_script_preamble."\n", 2) |
44
|
|
|
|
|
|
|
} else { |
45
|
1
|
|
|
|
|
3
|
('', 1) |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
}; |
48
|
2
|
|
|
|
|
8
|
return $shebang.$self->exclude_dev_preamble."\n#line ${line}\n".$data; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |