blib/lib/App/ThinPacker.pm

filter: Statementstmt 50.0% 18 / 36 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 2 totaltotal 33.8% 24 / 71 CC 10 SCAR 38.9
CC
10
Cov
32%
run
90.0
usage
6.0
BEGIN
1.0
CRAP 48.7
↑ Summary
1 package App::ThinPacker;
2 1 ▶use 5.8.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =pod
5  
6 =head1 NAME
7  
8 App::ThinPacker - enable your scripts to autoinstall their dependencies
9  
10 =head1 DESCRIPTION
11  
12 Enables your scripts to autoinstall their dependencies by injecting a small piece of code which downloads L<cpanminus> and uses it to install all the depenencies.
13  
14 =head1 SYNOPSIS
15  
16 thinpack your-script.pl > your-script-dist.pl
17  
18 =head1 SEE ALSO
19  
20 L<App::FatPacker>
21  
22 L<App::cpanminus>
23  
24 =head1 BUGS AND TODO
25  
26 =over 4
27  
28 =item No Windows support
29  
30 =item Rudimentary parsing
31  
32 =item Default --sudo for cpanm
33  
34 =item Downloading cpanm from third-party source
35  
36 =back
37  
38 =head1 AUTHOR
39  
40 Alex Kapranoff E<lt>kappa@cpan.orgE<gt>
41  
42 =head1 CONTRIBUTORS
43  
44 Alexey Surikov E<lt>ksuri@cpan.orgE<gt>
45  
46 =head1 LICENSE
47  
48 This program is free software, you can redistribute it under the same terms as Perl itself.
49  
50 =cut
51  
52 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 1 ▶use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 ▶use Pod::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 1 our $VERSION = '0.11';
60  
61 0 ▶sub run {
Subroutine run: not called CC=9 SCAR=45.0
Pod undocumented
62 0 ▶ my $arg = shift or usage();
Branch: 1 branch
BranchTrueFalseTotal
my $arg = shift() or usage() 0 0 0
63 0 ▶ usage(2) if $arg eq '-h' or $arg eq '--help';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "-h" or $arg eq "--help" 0 0 0
Condition0%0/3
$arg eq "-h" or $arg eq "--help"
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg eq "-h" or $arg eq "--help"
$arg eq "-h" $arg eq "--help"
Truth table0%0/3
A or B
A= $arg eq "-h"B= $arg eq "--help"
ABresult
1X1
011
000
64  
65 0 ▶ my $ppi = PPI::Document->new($arg) or usage();
Branch: 1 branch
BranchTrueFalseTotal
my $ppi = "PPI::Document"->new($arg) or usage() 0 0 0
66 0 my $includes = $ppi->find('Statement::Include');
67  
68 my $deps = join ' ',
69 0 grep { $_ !~ /^(?:strict|warnings|diagnostics|base|integer)$/ }
70 0 map { $_->module }
71 @$includes;
72  
73 0 my $inject = join '', map { s/%%DEPS%%/$deps/; $_ } <DATA>;
74  
75 0 ▶ open my $script, '<', $arg or exit print "Cannot open $arg: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $script, "<", $arg or exit print("Cannot open ${arg}: $!\n") 0 0 0
76 0 my $not_injected = 1;
77 0 ▶ while (my $line = <$script>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $script)) 0 0 0
78 0 ▶ if ($line =~ /^use / && $not_injected) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^use / and $not_injected) 0 0 0
Condition0%0/3
$line =~ /^use / and $not_injected
!ll&&!rl&&r
000
MC/DC0%0/2
$line =~ /^use / and $not_injected
$line =~ /^use / $not_injected
Truth table0%0/3
A and B
A= $line =~ /^use /B= $not_injected
ABresult
0X0
100
111
79 0 print "BEGIN {\n$inject\n}\n";
80 0 $not_injected = 0;
81 }
82  
83 0 print $line;
84 }
85 }
86  
87 0 ▶sub usage {
Subroutine usage: not called CC=2 SCAR=17.9
Pod undocumented
88 0 ▶ pod2usage(
Condition0%0/2
$_[0] || 0
l!l
00
MC/DC0%0/1
$_[0] || 0
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
89 -verbose => $_[0] || 0,
90 -output => \*STDERR,
91 -input => Pod::Find::pod_where(
92 { -inc => 1 },
93 __PACKAGE__,
94 ),
95 );
96 }
97  
98 __DATA__
↑ Summary