bin/ptardiff

filter: Statementstmt 93.5% 29 / 31 Branchbran 50.0% 8 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod n/a totaltotal 79.2% 42 / 53 CC 2 SCAR 3.9
CC
2
Cov
79%
BEGIN
2.1
usage
2.0
BEGIN
1.0
CRAP 1.5
« lib/Archive/Tar/Constant.pm ↑ Summary bin/ptar »
1 #!/usr/bin/perl
2  
3 1 ▶BEGIN { pop @INC if $INC[-1] eq '.' }
Subroutine BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
if $INC[-1] eq "." 1 0 1
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Archive::Tar;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Getopt::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 my $opts = {};
10 1 ▶getopts('h:', $opts) or die usage();
Branch: 1 branch
BranchTrueFalseTotal
&getopts("h:", $opts) or die usage() 1 0 1
11  
12 1 ▶die usages() if $opts->{h};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"h"} 0 1 1
13  
14 ### need Text::Diff -- give a polite error (not a standard prereq)
15 1 ▶unless ( eval { require Text::Diff; Text::Diff->import; 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require Text::Diff; "Text::Diff"->import; 1 } }) 0 1 1
16 0 die "\n\t This tool requires the 'Text::Diff' module to be installed\n";
17 }
18  
19 1 ▶my $arch = shift or die usage();
Branch: 1 branch
BranchTrueFalseTotal
my $arch = shift @ARGV or die usage() 1 0 1
20 1 ▶my $tar = Archive::Tar->new( $arch ) or die "Couldn't read '$arch': $!";
Branch: 1 branch
BranchTrueFalseTotal
my $tar = "Archive::Tar"->new($arch) or die "Couldn't read '${arch}': $!" 1 0 1
21  
22  
23 1 foreach my $file ( $tar->get_files ) {
24 2 ▶ next unless $file->is_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file->is_file 0 2 2
25 2 my $prefix = $file->prefix;
26 2 my $name = $file->name;
27 2 ▶ if (defined $prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prefix) 2 0 2
28 2 $name = File::Spec->catfile($prefix, $name);
29 }
30  
31 2 diff( \($file->get_content), $name,
32 { FILENAME_A => $name,
33 MTIME_A => $file->mtime,
34 OUTPUT => \*STDOUT
35 }
36 );
37 }
38  
39  
40  
41  
42 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
43 0 return q[
44  
45 Usage: ptardiff ARCHIVE_FILE
46 ptardiff -h
47  
48 ptardiff is a small program that diffs an extracted archive
49 against an unextracted one, using the perl module Archive::Tar.
50  
51 This effectively lets you view changes made to an archives contents.
52  
53 Provide the progam with an ARCHIVE_FILE and it will look up all
54 the files with in the archive, scan the current working directory
55 for a file with the name and diff it against the contents of the
56 archive.
57  
58  
59 Options:
60 h Prints this help message
61  
62  
63 Sample Usage:
64  
65 $ tar -xzf Acme-Buffy-1.3.tar.gz
66 $ vi Acme-Buffy-1.3/README
67  
68 [...]
69  
70 $ ptardiff Acme-Buffy-1.3.tar.gz > README.patch
71  
72  
73 See Also:
74 tar(1)
75 ptar
76 Archive::Tar
77  
78 ] . $/;
79 }
80  
81  
82  
83 =head1 NAME
84  
85 ptardiff - program that diffs an extracted archive against an unextracted one
86  
87 =head1 DESCRIPTION
88  
89 ptardiff is a small program that diffs an extracted archive
90 against an unextracted one, using the perl module Archive::Tar.
91  
92 This effectively lets you view changes made to an archives contents.
93  
94 Provide the progam with an ARCHIVE_FILE and it will look up all
95 the files with in the archive, scan the current working directory
96 for a file with the name and diff it against the contents of the
97 archive.
98  
99 =head1 SYNOPSIS
100  
101 ptardiff ARCHIVE_FILE
102 ptardiff -h
103  
104 $ tar -xzf Acme-Buffy-1.3.tar.gz
105 $ vi Acme-Buffy-1.3/README
106 [...]
107 $ ptardiff Acme-Buffy-1.3.tar.gz > README.patch
108  
109  
110 =head1 OPTIONS
111  
112 h Prints this help message
113  
114 =head1 SEE ALSO
115  
116 tar(1), L<Archive::Tar>.
117  
118 =cut
« lib/Archive/Tar/Constant.pm ↑ Summary bin/ptar »