script/file_unpack2

filter: Statementstmt 66.6% 54 / 81 Branchbran 33.3% 16 / 48 Conditioncond 30.4% 7 / 23 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 80.0% 8 / 10 Podpod n/a totaltotal 49.4% 86 / 174 CC 1 SCAR 1.8
CC
1
Cov
51%
__ANON__
2.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.2
« lib/File/Unpack2.pm ↑ Summary
1 #!/usr/bin/env perl
2 #
3 # file_unpack2 -- Command line front-end for File::Unpack2.
4 #
5 # (C) 2010-2014, jnw@cpan.org, all rights reserved.
6 # Distribute under the same license as Perl itself.
7 #
8  
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 $Data::Dumper::Terse = 1;
14 2 $Data::Dumper::Indent = 1;
15 2 ▶use Getopt::Long qw(:config no_ignore_case);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use File::Unpack2;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 my $version = $File::Unpack2::VERSION;
20 2 my @exclude;
21 2 my $exclude_vcs = 1;
22 2 my $help;
23 my $mime_only;
24 2 my $list_only;
25 2 my $list_perlish;
26 2 my @mime_helper_dirs;
27  
28 2 my %opt = ( verbose => 1, maxfilesize => '2.6G', one_shot => 1, no_op => 0, world_readable => 0, log_fullpath => 0, archive_name_as_dir => 0, follow_file_symlinks => 0, log_type => 'PLAIN');
29  
30 2 ▶$opt{one_shot} = 0 if $0 =~ m{deep[^/]*$};
Branch: 1 branch
BranchTrueFalseTotal
if $0 =~ m[deep[^/]*$] 0 2 2
31  
32 GetOptions(
33 "verbose|v+" => \$opt{verbose},
34 0 ▶ "version|V" => sub { print "$version\n"; exit },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 2 ▶ "quiet" => sub { $opt{verbose} = 0; },
Subroutine __ANON__: called CC=1 SCAR=0.0
36 "destdir|D|C=s" => \$opt{destdir},
37 "exclude|E=s" => \@exclude,
38 "exclude-vcs!" => \$exclude_vcs,
39 0 ▶ "vcs|include-vcs!" => sub { $exclude_vcs = !$_[1]; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 "help|?" => \$help,
41 "logfile|L=s" => \$opt{logfile},
42 "fullpath-log|F" => \$opt{log_fullpath},
43 "one-shot|one_shot|1" => \$opt{one_shot},
44 2 ▶ "deep|recursive" => sub { $opt{one_shot} = 0; },
Subroutine __ANON__: called CC=1 SCAR=0.0
45 "mimetype|m+" => \$mime_only,
46 "no_op|no-op|noop|n+" => \$opt{no_op},
47 "list-helpers|l+" => \$list_only,
48 "print-helpers|p+" => \$list_perlish,
49 2 "params|P=s" => \%{$opt{log_params}},
50 "maxfilesize=s" => \$opt{maxfilesize},
51 "use-mime-helper-dir|I|u=s" => \@mime_helper_dirs,
52 "world-readable|world_readable|R+" => \$opt{world_readable},
53 "archive-dirs|archive_dirs|A" => \$opt{archive_name_as_dir},
54 "follow-file-symlinks|f+" => \$opt{follow_file_symlinks},
55 2 ▶) or $help++;
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("verbose|v+", \$opt{"verbose"}, "version|V", sub { print "$version\n"; exit; } , "quiet", sub { $opt{"verbose"} = 0; } , "destdir|D|C=s", \$opt{"destdir"}, "exclude|E=s", \@exclude, "exclude-vcs!", \$exclude_vcs, "vcs|include-vcs!", sub { $exclude_vcs = !$_[1]; } , "help|?", \$help, "logfile|L=s", \$opt{"logfile"}, "fullpath-log|F", \$opt{"log_fullpath"}, "one-shot|one_shot|1", \$opt{"one_shot"}, "deep|recursive", sub { $opt{"one_shot"} = 0; } , "mimetype|m+", \$mime_only, "no_op|no-op|noop|n+", \$opt{"no_op"}, "list-helpers|l+", \$list_only, "print-helpers|p+", \$list_perlish, "params|P=s", \%{$opt{"log_params"};}, "maxfilesize=s", \$opt{"maxfilesize"}, "use-mime-helper-dir|I|u=s", \@mime_helper_dirs, "world-readable|world_readable|R+", \$opt{"world_readable"}, "archive-dirs|archive_dirs|A", \$opt{"archive_name_as_dir"}, "follow-file-symlinks|f+", \$opt{"follow_file_symlinks"}) or ++$help 2 0 2
56  
57 2 @mime_helper_dirs = split(/,/,join(',',@mime_helper_dirs));
58 2 ▶my $archive = shift or $list_perlish or $list_only or $help++;
Branch: 1 branch
BranchTrueFalseTotal
my $archive = shift @ARGV or $list_perlish or $list_only or ++$help 2 0 2
Condition33%2/6
my $archive = shift @ARGV or $list_perlish or $list_only
l!l&&r!l&&!r
200
my $archive = shift @ARGV or $list_perlish
l!l&&r!l&&!r
200
MC/DC0%0/3
my $archive = shift @ARGV or $list_perlish or $list_only
my $archive = shift @ARGV $list_perlish $list_only
Truth table25%1/4
A or B or C
A= my $archive = shift @ARGVB= $list_perlishC= $list_only
ABCresult
1XX1
01X1
0011
0000
59  
60 2 ▶pod2usage(-verbose => 1, -msg => "file_unpack2 V$version\n") if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 0 2 2
61  
62 2 ▶if (defined $opt{logfile})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{"logfile"}) 2 0 2
63 {
64 2 $opt{log_type} = 'JSON';
65 2 ▶ $opt{logfile} = \*STDOUT if $opt{logfile} eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"logfile"} eq "-" 0 2 2
66 }
67  
68 2 ▶$opt{logfile} ||= '/dev/null' if $list_only or $list_perlish or $mime_only or $opt{no_op};
Branch: 1 branch
BranchTrueFalseTotal
if $list_only or $list_perlish or $mime_only or $opt{"no_op"} 0 2 2
Condition27%3/11
$list_only or $list_perlish or $mime_only or $opt{"no_op"}
l!l&&r!l&&!r
002
$list_only or $list_perlish or $mime_only
l!l&&r!l&&!r
002
$list_only or $list_perlish
l!l&&r!l&&!r
002
$opt{"logfile"} ||= "/dev/null"
l!l
00
MC/DC0%0/4
$list_only or $list_perlish or $mime_only or $opt{"no_op"}
$list_only $list_perlish $mime_only $opt{"no_op"}
MC/DC0%0/1
$opt{"logfile"} ||= "/dev/null"
$opt{"logfile"}
Truth table20%1/5
A or B or C or D
A= $list_onlyB= $list_perlishC= $mime_onlyD= $opt{"no_op"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
Truth table0%0/2
A
A= $opt{"logfile"}
Aresult
11
00
69 2 my $u = File::Unpack2->new(%opt);
70 2 my $list = $u->mime_helper_dir(@mime_helper_dirs);
71  
72 2 ▶if ($list_perlish)
Branch: 1 branch
BranchTrueFalseTotal
if ($list_perlish) 0 2 2
73 {
74 0 print Dumper $list;
75 0 exit 0;
76 }
77  
78 2 ▶if ($list_only)
Branch: 1 branch
BranchTrueFalseTotal
if ($list_only) 0 2 2
79 {
80 0 printf @$_ for $u->list();
81 0 exit 0;
82 }
83  
84 2 ▶if ($mime_only)
Branch: 1 branch
BranchTrueFalseTotal
if ($mime_only) 0 2 2
85 {
86 0 ▶ $u->{verbose}-- if $u->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $u->{"verbose"} 0 0 0
87 0 ▶ if ($u->{verbose} > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($u->{"verbose"} > 1) 0 0 0
88 {
89 0 ▶ print "using File::LibMagic $File::LibMagic::VERSION\n" if defined $File::LibMagic::VERSION;
Branch: 1 branch
BranchTrueFalseTotal
if defined $File::LibMagic::VERSION 0 0 0
90 0 ▶ print "using File::MimeInfo::Magic $File::MimeInfo::Magic::VERSION\n" if defined $File::MimeInfo::Magic::VERSION;
Branch: 1 branch
BranchTrueFalseTotal
if defined $File::MimeInfo::Magic::VERSION 0 0 0
91 0 ▶ print "using File::Unpack2 $File::Unpack2::VERSION\n" if defined $File::Unpack2::VERSION;
Branch: 1 branch
BranchTrueFalseTotal
if defined $File::Unpack2::VERSION 0 0 0
92 }
93  
94 0 ▶ while (defined $archive)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $archive) 0 0 0
95 {
96 0 my $m = $u->mime($archive);
97 0 my ($h,$r) = $u->find_mime_helper($m);
98 0 ▶ if ($opt{verbose} > 1)
Branch: 2 branches
BranchTrueFalseTotal
if ($opt{'verbose'} > 1) { } 0 0 0
elsif ($opt{'verbose'} == 1) { } 0 0 0
99 {
100 0 print "$archive: ", Dumper $m;
101 0 print File::Unpack2::fmt_run_shellcmd($h) . "\n";
102 }
103 elsif ($opt{verbose} == 1)
104 {
105 0 print "$archive: $m->[0]; charset=$m->[1]\n";
106 }
107 else
108 {
109 0 print "$m->[0]\n";
110 }
111 0 $archive = shift;
112 }
113 0 exit 0;
114 }
115  
116 2 ▶while (defined $archive and !$u->{error})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $archive and not $u->{"error"}) 2 2 4
Condition66%2/3
defined $archive and not $u->{"error"}
!ll&&!rl&&r
202
MC/DC50%1/2
defined $archive and not $u->{"error"}
defined $archive not $u->{"error"}
Truth table66%2/3
A and not(B)
A= defined $archiveB= not $u->{"error"}
ABresult
0X0
100
111
117 {
118 2 $u->exclude(vcs => $exclude_vcs);
119 2 ▶ $u->exclude(add => \@exclude) if @exclude;
Branch: 1 branch
BranchTrueFalseTotal
if @exclude 0 2 2
120  
121 2 $u->unpack($archive);
122 2 ▶ map { print STDERR "ERROR: $_\n" } @{$u->{error}} if $u->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $u->{"error"} 1 1 2
123 2 $archive = shift;
124 2 ▶ if (defined($archive))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $archive) 0 2 2
125 {
126 0 ▶ if (defined $opt{logfile} and -f $opt{logfile})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{"logfile"} and -f $opt{"logfile"}) 0 0 0
Condition0%0/3
defined $opt{"logfile"} and -f $opt{"logfile"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opt{"logfile"} and -f $opt{"logfile"}
defined $opt{"logfile"} -f $opt{"logfile"}
Truth table0%0/3
A and B
A= defined $opt{"logfile"}B= -f $opt{"logfile"}
ABresult
0X0
100
111
127 {
128 0 ▶ warn "File::Unpack2($archive): overwriting previous logfile $opt{logfile} in 3 seconds. Press CTRL-C to abort.\n" if defined $archive;
Branch: 1 branch
BranchTrueFalseTotal
if defined $archive 0 0 0
129 0 sleep(3);
130 }
131 # reload, for the next round. (new() opens the logfile, unpack() closese it.)
132 0 $u = File::Unpack2->new(%opt);
133 0 $u->mime_helper_dir(@mime_helper_dirs);
134 }
135 }
136  
137 __END__
« lib/File/Unpack2.pm ↑ Summary