10 getopts('Ddcvzthxf:I', $opts) or die usage();
12 ### show the help message ###
13 die usage() if $opts->{h};
15 ### enable debugging (undocumented feature)
16 local $Archive::Tar::DEBUG = 1 if $opts->{d};
18 ### enable insecure extracting.
19 local $Archive::Tar::INSECURE_EXTRACT_MODE = 1 if $opts->{I};
22 unless ( 1 == grep { defined $opts->{$_} } qw[x t c] ) {
23 die "You need exactly one of 'x', 't' or 'c' options: " . usage();
26 my $compress = $opts->{z} ? 1 : 0;
27 my $verbose = $opts->{v} ? 1 : 0;
28 my $file = $opts->{f} ? $opts->{f} : 'default.tar';
29 my $tar = Archive::Tar->new();
34 find( sub { push @files, $File::Find::name;
35 print $File::Find::name.$/ if $verbose }, @ARGV );
39 $file = IO::Handle->new();
40 $file->fdopen(fileno(STDOUT),"w");
43 Archive::Tar->create_archive( $file, $compress, @files );
48 $file = IO::Handle->new();
49 $file->fdopen(fileno(STDIN),"r");
52 ### print the files we're finding?
53 my $print = $verbose || $opts->{'t'} || 0;
55 my $iter = Archive::Tar->iter( $file );
57 while( my $f = $iter->() ) {
58 print $f->full_path . $/ if $print;
60 ### data dumper output
61 print Dumper( $f ) if $opts->{'D'};
64 $f->extract if $opts->{'x'};
68 ### pod & usage in one
70 my $usage .= << '=cut';
75 ptar - a tar-like program written in perl
79 ptar is a small, tar look-alike program that uses the perl module
80 Archive::Tar to extract, create and list tar archives.
84 ptar -c [-v] [-z] [-f ARCHIVE_FILE | -] FILE FILE ...
85 ptar -x [-v] [-z] [-f ARCHIVE_FILE | -]
86 ptar -t [-z] [-f ARCHIVE_FILE | -]
91 c Create ARCHIVE_FILE or STDOUT (-) from FILE
92 x Extract from ARCHIVE_FILE or STDIN (-)
93 t List the contents of ARCHIVE_FILE or STDIN (-)
94 f Name of the ARCHIVE_FILE to use. Default is './default.tar'
95 z Read/Write zlib compressed ARCHIVE_FILE (not always available)
96 v Print filenames as they are added or extraced from ARCHIVE_FILE
97 h Prints this help message
101 tar(1), L<Archive::Tar>.
105 ### strip the pod directives
106 $usage =~ s/=pod\n//g;
107 $usage =~ s/=head1 //g;
109 ### add some newlines