This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
new perldelta
[perl5.git] / cpan / Archive-Tar / bin / ptardiff
1 #!/usr/bin/perl
2
3 BEGIN { pop @INC if $INC[-1] eq '.' }
4 use strict;
5 use warnings;
6 use Archive::Tar;
7 use Getopt::Std;
8
9 my $opts = {};
10 getopts('h:', $opts) or die usage();
11
12 die usages() if $opts->{h};
13
14 ### need Text::Diff -- give a polite error (not a standard prereq)
15 unless ( eval { require Text::Diff; Text::Diff->import; 1 } ) {
16     die "\n\t This tool requires the 'Text::Diff' module to be installed\n";
17 }
18
19 my $arch = shift                        or die usage();
20 my $tar  = Archive::Tar->new( $arch )   or die "Couldn't read '$arch': $!";
21
22
23 foreach my $file ( $tar->get_files ) {
24     next unless $file->is_file;
25     my $prefix = $file->prefix;
26     my $name = $file->name;
27     if (defined $prefix) {
28         $name = File::Spec->catfile($prefix, $name);
29     }
30
31     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     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