bin/ptar

filter: Statementstmt 79.2% 61 / 77 Branchbran 65.3% 34 / 52 Conditioncond 78.5% 11 / 14 MC/DCmcdc 57.1% 4 / 7 Subroutinesub 90.9% 10 / 11 Podpod n/a totaltotal 74.5% 120 / 161 CC 3 SCAR 3.4
CC
3
Cov
74%
BEGIN
2.1
__ANON__
2.0
usage
2.0
CRAP 1.4
« bin/ptardiff ↑ Summary
1 #!/usr/bin/perl
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶BEGIN { pop @INC if $INC[-1] eq '.' }
Subroutine BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
if $INC[-1] eq "." 5 0 5
6 5 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Getopt::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Archive::Tar;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # Allow (and ignore) --format=ustar, for compatibility with GNU tar
12 5 ▶for (my $i = 0; $i < @ARGV; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @ARGV) 17 5 22
13 17 ▶ last if $ARGV[$i] eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if $ARGV[$i] eq "--" 0 17 17
14 17 ▶ splice @ARGV, $i--, 1 if $ARGV[$i] eq '--format=ustar';
Branch: 1 branch
BranchTrueFalseTotal
if $ARGV[$i] eq "--format=ustar" 1 16 17
15 17 ▶ splice @ARGV, $i--, 2 if $i < $#ARGV
Branch: 1 branch
BranchTrueFalseTotal
if $i < $#ARGV and $ARGV[$i] eq "--format" and $ARGV[$i + 1] eq "ustar" 1 16 17
Condition83%5/6
$i < $#ARGV and $ARGV[$i] eq "--format" and $ARGV[$i + 1] eq "ustar"
!ll&&!rl&&r
1601
$i < $#ARGV and $ARGV[$i] eq "--format"
!ll&&!rl&&r
5111
MC/DC66%2/3
$i < $#ARGV and $ARGV[$i] eq "--format" and $ARGV[$i + 1] eq "ustar"
$i < $#ARGV $ARGV[$i] eq "--format" $ARGV[$i + 1] eq "ustar"
Truth table75%3/4
A and B and C
A= $i < $#ARGVB= $ARGV[$i] eq "--format"C= $ARGV[$i + 1] eq "ustar"
ABCresult
0XX0
10X0
1100
1111
16 && $ARGV[$i] eq '--format' && $ARGV[$i + 1] eq 'ustar';
17 }
18  
19 # Allow historic support for dashless bundled options
20 # tar cvf file.tar
21 # is valid (GNU) tar style
22 @ARGV && $ARGV[0] =~ m/^[DdcvzthxIC]+[fT]?$/ and
23 5 ▶ unshift @ARGV, map { "-$_" } split m// => shift @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
@ARGV and $ARGV[0] =~ /^[DdcvzthxIC]+[fT]?$/ and unshift @ARGV, map({"-$_";} split(//, shift @ARGV, 0)) 1 4 5
Condition66%2/3
@ARGV and $ARGV[0] =~ /^[DdcvzthxIC]+[fT]?$/
!ll&&!rl&&r
041
MC/DC50%1/2
@ARGV and $ARGV[0] =~ /^[DdcvzthxIC]+[fT]?$/
@ARGV $ARGV[0] =~ /^[DdcvzthxIC]+[fT]?$/
Truth table66%2/3
A and B
A= @ARGVB= $ARGV[0] =~ /^[DdcvzthxIC]+[fT]?$/
ABresult
0X0
100
111
24 5 my $opts = {};
25 5 ▶getopts('Ddcvzthxf:ICT:', $opts) or die usage();
Branch: 1 branch
BranchTrueFalseTotal
&getopts("Ddcvzthxf:ICT:", $opts) or die usage() 5 0 5
26  
27 ### show the help message ###
28 5 ▶die usage() if $opts->{h};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"h"} 0 5 5
29  
30 ### enable debugging (undocumented feature)
31 5 ▶local $Archive::Tar::DEBUG = 1 if $opts->{d};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"d"} 0 5 5
32  
33 ### enable insecure extracting.
34 5 ▶local $Archive::Tar::INSECURE_EXTRACT_MODE = 1 if $opts->{I};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"I"} 0 5 5
35  
36 ### sanity checks ###
37 5 ▶unless ( 1 == grep { defined $opts->{$_} } qw[x t c] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (1 == grep({defined $opts->{$_};} "x", "t", "c")) 0 5 5
38 0 die "You need exactly one of 'x', 't' or 'c' options: " . usage();
39 }
40  
41 5 ▶my $compress = $opts->{z} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'z'} ? : 0 5 5
42 5 ▶my $verbose = $opts->{v} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'v'} ? : 1 4 5
43 5 ▶my $file = $opts->{f} ? $opts->{f} : 'default.tar';
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'f'} ? : 5 0 5
44 5 my $tar = Archive::Tar->new();
45  
46 5 ▶if( $opts->{c} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'c'}) { } 3 2 5
47 3 my @files;
48 3 my @src = @ARGV;
49 3 ▶ if( $opts->{T} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"T"}) 0 3 3
50 0 ▶ if( $opts->{T} eq "-" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'T'} eq '-') { } 0 0 0
elsif (open my $fh, '<', $opts->{'T'}) { } 0 0 0
51 0 chomp( @src = <STDIN> );
52 } elsif( open my $fh, "<", $opts->{T} ) {
53 0 chomp( @src = <$fh> );
54 } else {
55 0 die "$0: $opts->{T}: $!\n";
56 }
57 }
58  
59 3 ▶ find( sub { push @files, $File::Find::name;
Subroutine __ANON__: called CC=2 SCAR=6.9
60 3 ▶ print $File::Find::name.$/ if $verbose }, @src );
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 1 2 3
61  
62 3 ▶ if ($file eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($file eq "-") 0 3 3
63 5 ▶ use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 0 $file = IO::Handle->new();
65 0 $file->fdopen(fileno(STDOUT),"w");
66 }
67  
68 3 my $tar = Archive::Tar->new;
69 3 $tar->add_files(@files);
70 3 ▶ if( $opts->{C} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"C"}) 0 3 3
71 0 for my $f ($tar->get_files) {
72 0 $f->mode($f->mode & ~022); # chmod go-w
73 }
74 }
75 3 $tar->write($file, $compress);
76 } else {
77 2 ▶ if ($file eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($file eq "-") 0 2 2
78 5 ▶ use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 0 $file = IO::Handle->new();
80 0 $file->fdopen(fileno(STDIN),"r");
81 }
82  
83 ### print the files we're finding?
84 2 ▶ my $print = $verbose || $opts->{'t'} || 0;
Condition80%4/5
$verbose || $opts->{'t'} || 0
l!l
11
$verbose or $opts->{"t"}
l!l&&r!l&&!r
011
MC/DC50%1/2
$verbose || $opts->{'t'} || 0
$verbose $opts->{"t"}
Truth table66%2/3
A or B
A= $verboseB= $opts->{"t"}
ABresult
1X1
011
000
85  
86 2 my $iter = Archive::Tar->iter( $file );
87  
88 2 ▶ while( my $f = $iter->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = &$iter()) 2 2 4
89 2 ▶ print $f->full_path . $/ if $print;
Branch: 1 branch
BranchTrueFalseTotal
if $print 1 1 2
90  
91 ### data dumper output
92 2 ▶ print Dumper( $f ) if $opts->{'D'};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"D"} 0 2 2
93  
94 ### extract it
95 2 ▶ $f->extract if $opts->{'x'};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"x"} 1 1 2
96 }
97 }
98  
99 ### pod & usage in one
100 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
101 0 my $usage .= << '=cut';
102 =pod
103  
104 =head1 NAME
105  
106 ptar - a tar-like program written in perl
107  
108 =head1 DESCRIPTION
109  
110 ptar is a small, tar look-alike program that uses the perl module
111 Archive::Tar to extract, create and list tar archives.
112  
113 =head1 SYNOPSIS
114  
115 ptar -c [-v] [-z] [-C] [-f ARCHIVE_FILE | -] FILE FILE ...
116 ptar -c [-v] [-z] [-C] [-T index | -] [-f ARCHIVE_FILE | -]
117 ptar -x [-v] [-z] [-f ARCHIVE_FILE | -]
118 ptar -t [-z] [-f ARCHIVE_FILE | -]
119 ptar -h
120  
121 =head1 OPTIONS
122  
123 c Create ARCHIVE_FILE or STDOUT (-) from FILE
124 x Extract from ARCHIVE_FILE or STDIN (-)
125 t List the contents of ARCHIVE_FILE or STDIN (-)
126 f Name of the ARCHIVE_FILE to use. Default is './default.tar'
127 z Read/Write zlib compressed ARCHIVE_FILE (not always available)
128 v Print filenames as they are added or extracted from ARCHIVE_FILE
129 h Prints this help message
130 C CPAN mode - drop 022 from permissions
131 T get names to create from file
132  
133 =head1 SEE ALSO
134  
135 L<tar(1)>, L<Archive::Tar>.
136  
137 =cut
138  
139 ### strip the pod directives
140 0 $usage =~ s/=pod\n//g;
141 0 $usage =~ s/=head1 //g;
142  
143 ### add some newlines
144 0 $usage .= $/.$/;
145  
146 0 return $usage;
147 }
148  
« bin/ptardiff ↑ Summary