perlsub's docs on state assignment are busted
[p5sagit/p5-mst-13.2.git] / lib / Archive / Tar / bin / ptar
CommitLineData
291d3373 1#!/usr/bin/perl
2use strict;
3
4use Getopt::Std;
5use Archive::Tar;
6use File::Find;
7
8my $opts = {};
9getopts('dcvzthxf:', $opts) or die usage();
10
11### show the help message ###
12die usage() if $opts->{h};
13
14### enable debugging (undocumented feature)
15local $Archive::Tar::DEBUG = 1 if $opts->{d};
16
17### sanity checks ###
18unless ( 1 == grep { defined $opts->{$_} } qw[x t c] ) {
19 die "You need exactly one of 'x', 't' or 'c' options: " . usage();
20}
21
22my $compress = $opts->{z} ? 1 : 0;
23my $verbose = $opts->{v} ? 1 : 0;
24my $file = $opts->{f} ? $opts->{f} : 'default.tar';
25my $tar = Archive::Tar->new();
26
27if( $opts->{c} ) {
28 my @files;
29 find( sub { push @files, $File::Find::name;
30 print $File::Find::name.$/ if $verbose }, @ARGV );
b90ab6b2 31
32 Archive::Tar->create_archive( $file, $compress, @files );
291d3373 33 exit;
b90ab6b2 34}
291d3373 35
36my $tar = Archive::Tar->new($file, $compress);
37
38if( $opts->{t} ) {
b90ab6b2 39 print map { $_->full_path . $/ } $tar->get_files;
291d3373 40
b90ab6b2 41} elsif( $opts->{x} ) {
291d3373 42 print map { $_->full_path . $/ } $tar->get_files
43 if $verbose;
44 Archive::Tar->extract_archive($file, $compress);
b90ab6b2 45}
291d3373 46
47
48
49sub usage {
50 qq[
b90ab6b2 51Usage: ptar -c [-v] [-z] [-f ARCHIVE_FILE] FILE FILE ...
52 ptar -x [-v] [-z] [-f ARCHIVE_FILE]
53 ptar -t [-z] [-f ARCHIVE_FILE]
291d3373 54 ptar -h
b90ab6b2 55
291d3373 56 ptar is a small, tar look-alike program that uses the perl module
b90ab6b2 57 Archive::Tar to extract, create and list tar archives.
58
291d3373 59Options:
60 x Extract from ARCHIVE_FILE
61 c Create ARCHIVE_FILE from FILE
62 t List the contents of ARCHIVE_FILE
63 f Name of the ARCHIVE_FILE to use. Default is './default.tar'
64 z Read/Write zlib compressed ARCHIVE_FILE (not always available)
65 v Print filenames as they are added or extraced from ARCHIVE_FILE
66 h Prints this help message
67
68See Also:
69 tar(1)
70 Archive::Tar
71
72 \n]
73}
74
b90ab6b2 75=head1 NAME
76
77ptar - a tar-like program written in perl
78
79=head1 DESCRIPTION
80
81ptar is a small, tar look-alike program that uses the perl module
82Archive::Tar to extract, create and list tar archives.
83
84=head1 SYNOPSIS
85
86 ptar -c [-v] [-z] [-f ARCHIVE_FILE] FILE FILE ...
87 ptar -x [-v] [-z] [-f ARCHIVE_FILE]
88 ptar -t [-z] [-f ARCHIVE_FILE]
89 ptar -h
90
91=head1 OPTIONS
92
93 x Extract from ARCHIVE_FILE
94 c Create ARCHIVE_FILE from FILE
95 t List the contents of ARCHIVE_FILE
96 f Name of the ARCHIVE_FILE to use. Default is './default.tar'
97 z Read/Write zlib compressed ARCHIVE_FILE (not always available)
98 v Print filenames as they are added or extraced from ARCHIVE_FILE
99 h Prints this help message
100
101=head1 SEE ALSO
102
103tar(1), L<Archive::Tar>.
104
105=cut