File Coverage

bin/ptardiff
Criterion Covered Total %
statement 29 31 93.5
branch 8 16 50.0
condition n/a
subroutine 5 6 83.3
pod n/a
total 42 53 79.2


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3 1 50   1   4236 BEGIN { pop @INC if $INC[-1] eq '.' }
4 1     1   6 use strict;
  1         1  
  1         17  
5 1     1   7 use warnings;
  1         1  
  1         34  
6 1     1   795 use Archive::Tar;
  1         3  
  1         53  
7 1     1   431 use Getopt::Std;
  1         1778  
  1         3083  
8              
9 1         137267 my $opts = {};
10 1 50       7 getopts('h:', $opts) or die usage();
11              
12 1 50       27 die usages() if $opts->{h};
13              
14             ### need Text::Diff -- give a polite error (not a standard prereq)
15 1 50       1 unless ( eval { require Text::Diff; Text::Diff->import; 1 } ) {
  1         499  
  1         9418  
  1         6  
16 0         0 die "\n\t This tool requires the 'Text::Diff' module to be installed\n";
17             }
18              
19 1 50       5 my $arch = shift or die usage();
20 1 50       9 my $tar = Archive::Tar->new( $arch ) or die "Couldn't read '$arch': $!";
21              
22              
23 1         6 foreach my $file ( $tar->get_files ) {
24 2 50       689 next unless $file->is_file;
25 2         6 my $prefix = $file->prefix;
26 2         5 my $name = $file->name;
27 2 50       6 if (defined $prefix) {
28 2         40 $name = File::Spec->catfile($prefix, $name);
29             }
30              
31 2         9 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             sub usage {
43 0     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.
117              
118             =cut