This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update perlfaq to CPAN version 5.021011
[perl5.git] / cpan / Archive-Tar / lib / Archive / Tar / Constant.pm
CommitLineData
39713df4
RGS
1package Archive::Tar::Constant;
2
3BEGIN {
4 require Exporter;
93e94d8a 5
19606b44 6 $VERSION = '2.04';
642eb381 7 @ISA = qw[Exporter];
39713df4
RGS
8
9 require Time::Local if $^O eq "MacOS";
10}
11
501bd44a 12@EXPORT = Archive::Tar::Constant->_list_consts( __PACKAGE__ );
642eb381 13
39713df4
RGS
14use constant FILE => 0;
15use constant HARDLINK => 1;
16use constant SYMLINK => 2;
17use constant CHARDEV => 3;
18use constant BLOCKDEV => 4;
19use constant DIR => 5;
20use constant FIFO => 6;
21use constant SOCKET => 8;
22use constant UNKNOWN => 9;
23use constant LONGLINK => 'L';
24use constant LABEL => 'V';
25
26use constant BUFFER => 4096;
27use constant HEAD => 512;
28use constant BLOCK => 512;
29
642eb381
SH
30use constant COMPRESS_GZIP => 9;
31use constant COMPRESS_BZIP => 'bzip2';
32
39713df4
RGS
33use constant BLOCK_SIZE => sub { my $n = int($_[0]/BLOCK); $n++ if $_[0] % BLOCK; $n * BLOCK };
34use constant TAR_PAD => sub { my $x = shift || return; return "\0" x (BLOCK - ($x % BLOCK) ) };
35use constant TAR_END => "\0" x BLOCK;
36
37use constant READ_ONLY => sub { shift() ? 'rb' : 'r' };
38use constant WRITE_ONLY => sub { $_[0] ? 'wb' . shift : 'w' };
39use constant MODE_READ => sub { $_[0] =~ /^r/ ? 1 : 0 };
40
3c4b39be 41# Pointless assignment to make -w shut up
39713df4
RGS
42my $getpwuid; $getpwuid = 'unknown' unless eval { my $f = getpwuid (0); };
43my $getgrgid; $getgrgid = 'unknown' unless eval { my $f = getgrgid (0); };
97a504ba
RGS
44use constant UNAME => sub { $getpwuid || scalar getpwuid( shift() ) || '' };
45use constant GNAME => sub { $getgrgid || scalar getgrgid( shift() ) || '' };
39713df4
RGS
46use constant UID => $>;
47use constant GID => (split ' ', $) )[0];
48
49use constant MODE => do { 0666 & (0777 & ~umask) };
50use constant STRIP_MODE => sub { shift() & 0777 };
51use constant CHECK_SUM => " ";
52
f8c9502f 53use constant UNPACK => 'A100 A8 A8 A8 a12 A12 A8 A1 A100 A6 A2 A32 A32 A8 A8 A155 x12'; # cdrake - size must be a12 - not A12 - or else screws up huge file sizes (>8gb)
39713df4
RGS
54use constant PACK => 'a100 a8 a8 a8 a12 a12 A8 a1 a100 a6 a2 a32 a32 a8 a8 a155 x12';
55use constant NAME_LENGTH => 100;
56use constant PREFIX_LENGTH => 155;
57
93e94d8a 58use constant TIME_OFFSET => ($^O eq "MacOS") ? Time::Local::timelocal(0,0,0,1,0,70) : 0;
39713df4
RGS
59use constant MAGIC => "ustar";
60use constant TAR_VERSION => "00";
61use constant LONGLINK_NAME => '././@LongLink';
642eb381 62use constant PAX_HEADER => 'pax_global_header';
39713df4 63
642eb381 64 ### allow ZLIB to be turned off using ENV: DEBUG only
81a5970e
RGS
65use constant ZLIB => do { !$ENV{'PERL5_AT_NO_ZLIB'} and
66 eval { require IO::Zlib };
93e94d8a 67 $ENV{'PERL5_AT_NO_ZLIB'} || $@ ? 0 : 1
642eb381
SH
68 };
69
93e94d8a 70 ### allow BZIP to be turned off using ENV: DEBUG only
642eb381
SH
71use constant BZIP => do { !$ENV{'PERL5_AT_NO_BZIP'} and
72 eval { require IO::Uncompress::Bunzip2;
73 require IO::Compress::Bzip2; };
93e94d8a 74 $ENV{'PERL5_AT_NO_BZIP'} || $@ ? 0 : 1
642eb381
SH
75 };
76
39713df4 77use constant GZIP_MAGIC_NUM => qr/^(?:\037\213|\037\235)/;
642eb381 78use constant BZIP_MAGIC_NUM => qr/^BZh\d/;
39713df4 79
2610e7a4 80use constant CAN_CHOWN => sub { ($> == 0 and $^O ne "MacOS" and $^O ne "MSWin32") };
39713df4
RGS
81use constant CAN_READLINK => ($^O ne 'MSWin32' and $^O !~ /RISC(?:[ _])?OS/i and $^O ne 'VMS');
82use constant ON_UNIX => ($^O ne 'MSWin32' and $^O ne 'MacOS' and $^O ne 'VMS');
93e94d8a 83use constant ON_VMS => $^O eq 'VMS';
39713df4 84
501bd44a
CBW
85sub _list_consts {
86 my $class = shift;
87 my $pkg = shift;
88 return unless defined $pkg; # some joker might use '0' as a pkg...
89
90 my @rv;
91 { no strict 'refs';
92 my $stash = $pkg . '::';
93
94 for my $name (sort keys %$stash ) {
95
96 ### is it a subentry?
97 my $sub = $pkg->can( $name );
98 next unless defined $sub;
99
100 next unless defined prototype($sub) and
101 not length prototype($sub);
102
103 push @rv, $name;
104 }
105 }
106
107 return sort @rv;
108}
109
39713df4 1101;