3 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
4 if 0; # not running under some shell
13 getopts('Ddcvzthxf:I', $opts) or die usage();
15 ### show the help message ###
16 die usage() if $opts->{h};
18 ### enable debugging (undocumented feature)
19 local $Archive::Tar::DEBUG = 1 if $opts->{d};
21 ### enable insecure extracting.
22 local $Archive::Tar::INSECURE_EXTRACT_MODE = 1 if $opts->{I};
25 unless ( 1 == grep { defined $opts->{$_} } qw[x t c] ) {
26 die "You need exactly one of 'x', 't' or 'c' options: " . usage();
29 my $compress = $opts->{z} ? 1 : 0;
30 my $verbose = $opts->{v} ? 1 : 0;
31 my $file = $opts->{f} ? $opts->{f} : 'default.tar';
32 my $tar = Archive::Tar->new();
37 find( sub { push @files, $File::Find::name;
38 print $File::Find::name.$/ if $verbose }, @ARGV );
42 $file = IO::Handle->new();
43 $file->fdopen(fileno(STDOUT),"w");
46 Archive::Tar->create_archive( $file, $compress, @files );
51 $file = IO::Handle->new();
52 $file->fdopen(fileno(STDIN),"r");
55 ### print the files we're finding?
56 my $print = $verbose || $opts->{'t'} || 0;
58 my $iter = Archive::Tar->iter( $file );
60 while( my $f = $iter->() ) {
61 print $f->full_path . $/ if $print;
63 ### data dumper output
64 print Dumper( $f ) if $opts->{'D'};
67 $f->extract if $opts->{'x'};
71 ### pod & usage in one
73 my $usage .= << '=cut';
78 ptar - a tar-like program written in perl
82 ptar is a small, tar look-alike program that uses the perl module
83 Archive::Tar to extract, create and list tar archives.
87 ptar -c [-v] [-z] [-f ARCHIVE_FILE | -] FILE FILE ...
88 ptar -x [-v] [-z] [-f ARCHIVE_FILE | -]
89 ptar -t [-z] [-f ARCHIVE_FILE | -]
94 c Create ARCHIVE_FILE or STDOUT (-) from FILE
95 x Extract from ARCHIVE_FILE or STDIN (-)
96 t List the contents of ARCHIVE_FILE or STDIN (-)
97 f Name of the ARCHIVE_FILE to use. Default is './default.tar'
98 z Read/Write zlib compressed ARCHIVE_FILE (not always available)
99 v Print filenames as they are added or extraced from ARCHIVE_FILE
100 h Prints this help message
104 tar(1), L<Archive::Tar>.
108 ### strip the pod directives
109 $usage =~ s/=pod\n//g;
110 $usage =~ s/=head1 //g;
112 ### add some newlines