1package Archive::Tar::Constant; 2 3BEGIN { 4 require Exporter; 5 6 $VERSION = '1.96'; 7 @ISA = qw[Exporter]; 8 9 require Time::Local if $^O eq "MacOS"; 10} 11 12@EXPORT = Archive::Tar::Constant->_list_consts( __PACKAGE__ ); 13 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 30use constant COMPRESS_GZIP => 9; 31use constant COMPRESS_BZIP => 'bzip2'; 32 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 41# Pointless assignment to make -w shut up 42my $getpwuid; $getpwuid = 'unknown' unless eval { my $f = getpwuid (0); }; 43my $getgrgid; $getgrgid = 'unknown' unless eval { my $f = getgrgid (0); }; 44use constant UNAME => sub { $getpwuid || scalar getpwuid( shift() ) || '' }; 45use constant GNAME => sub { $getgrgid || scalar getgrgid( shift() ) || '' }; 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 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) 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 58use constant TIME_OFFSET => ($^O eq "MacOS") ? Time::Local::timelocal(0,0,0,1,0,70) : 0; 59use constant MAGIC => "ustar"; 60use constant TAR_VERSION => "00"; 61use constant LONGLINK_NAME => '././@LongLink'; 62use constant PAX_HEADER => 'pax_global_header'; 63 64 ### allow ZLIB to be turned off using ENV: DEBUG only 65use constant ZLIB => do { !$ENV{'PERL5_AT_NO_ZLIB'} and 66 eval { require IO::Zlib }; 67 $ENV{'PERL5_AT_NO_ZLIB'} || $@ ? 0 : 1 68 }; 69 70 ### allow BZIP to be turned off using ENV: DEBUG only 71use constant BZIP => do { !$ENV{'PERL5_AT_NO_BZIP'} and 72 eval { require IO::Uncompress::Bunzip2; 73 require IO::Compress::Bzip2; }; 74 $ENV{'PERL5_AT_NO_BZIP'} || $@ ? 0 : 1 75 }; 76 77use constant GZIP_MAGIC_NUM => qr/^(?:\037\213|\037\235)/; 78use constant BZIP_MAGIC_NUM => qr/^BZh\d/; 79 80use constant CAN_CHOWN => sub { ($> == 0 and $^O ne "MacOS" and $^O ne "MSWin32") }; 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'); 83use constant ON_VMS => $^O eq 'VMS'; 84 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 1101; 111