1package Archive::Tar::Constant; 2 3BEGIN { 4 require Exporter; 5 6 $VERSION = '2.36'; 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 strict; 15use warnings; 16 17use constant FILE => 0; 18use constant HARDLINK => 1; 19use constant SYMLINK => 2; 20use constant CHARDEV => 3; 21use constant BLOCKDEV => 4; 22use constant DIR => 5; 23use constant FIFO => 6; 24use constant SOCKET => 8; 25use constant UNKNOWN => 9; 26use constant LONGLINK => 'L'; 27use constant LABEL => 'V'; 28 29use constant BUFFER => 4096; 30use constant HEAD => 512; 31use constant BLOCK => 512; 32 33use constant COMPRESS_GZIP => 9; 34use constant COMPRESS_BZIP => 'bzip2'; 35use constant COMPRESS_XZ => 'xz'; 36 37use constant BLOCK_SIZE => sub { my $n = int($_[0]/BLOCK); $n++ if $_[0] % BLOCK; $n * BLOCK }; 38use constant TAR_PAD => sub { my $x = shift || return; return "\0" x (BLOCK - ($x % BLOCK) ) }; 39use constant TAR_END => "\0" x BLOCK; 40 41use constant READ_ONLY => sub { shift() ? 'rb' : 'r' }; 42use constant WRITE_ONLY => sub { $_[0] ? 'wb' . shift : 'w' }; 43use constant MODE_READ => sub { $_[0] =~ /^r/ ? 1 : 0 }; 44 45# Pointless assignment to make -w shut up 46my $getpwuid; $getpwuid = 'unknown' unless eval { my $f = getpwuid (0); }; 47my $getgrgid; $getgrgid = 'unknown' unless eval { my $f = getgrgid (0); }; 48use constant UNAME => sub { $getpwuid || scalar getpwuid( shift() ) || '' }; 49use constant GNAME => sub { $getgrgid || scalar getgrgid( shift() ) || '' }; 50use constant UID => $>; 51use constant GID => (split ' ', $) )[0]; 52 53use constant MODE => do { 0666 & (0777 & ~umask) }; 54use constant STRIP_MODE => sub { shift() & 0777 }; 55use constant CHECK_SUM => " "; 56 57use 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) 58use constant PACK => 'a100 a8 a8 a8 a12 a12 A8 a1 a100 a6 a2 a32 a32 a8 a8 a155 x12'; 59use constant NAME_LENGTH => 100; 60use constant PREFIX_LENGTH => 155; 61 62use constant TIME_OFFSET => ($^O eq "MacOS") ? Time::Local::timelocal(0,0,0,1,0,1970) : 0; 63use constant MAGIC => "ustar"; 64use constant TAR_VERSION => "00"; 65use constant LONGLINK_NAME => '././@LongLink'; 66use constant PAX_HEADER => 'pax_global_header'; 67 68 ### allow ZLIB to be turned off using ENV: DEBUG only 69use constant ZLIB => do { !$ENV{'PERL5_AT_NO_ZLIB'} and 70 eval { require IO::Zlib }; 71 $ENV{'PERL5_AT_NO_ZLIB'} || $@ ? 0 : 1 72 }; 73 74 ### allow BZIP to be turned off using ENV: DEBUG only 75use constant BZIP => do { !$ENV{'PERL5_AT_NO_BZIP'} and 76 eval { require IO::Uncompress::Bunzip2; 77 require IO::Compress::Bzip2; }; 78 $ENV{'PERL5_AT_NO_BZIP'} || $@ ? 0 : 1 79 }; 80 81 ### allow XZ to be turned off using ENV: DEBUG only 82use constant XZ => do { !$ENV{'PERL5_AT_NO_XZ'} and 83 eval { require IO::Compress::Xz; 84 require IO::Uncompress::UnXz; }; 85 $ENV{'PERL5_AT_NO_XZ'} || $@ ? 0 : 1 86 }; 87 88use constant GZIP_MAGIC_NUM => qr/^(?:\037\213|\037\235)/; 89use constant BZIP_MAGIC_NUM => qr/^BZh\d/; 90use constant XZ_MAGIC_NUM => qr/^\xFD\x37\x7A\x58\x5A\x00/; 91 92use constant CAN_CHOWN => sub { ($> == 0 and $^O ne "MacOS" and $^O ne "MSWin32") }; 93use constant CAN_READLINK => ($^O ne 'MSWin32' and $^O !~ /RISC(?:[ _])?OS/i and $^O ne 'VMS'); 94use constant ON_UNIX => ($^O ne 'MSWin32' and $^O ne 'MacOS' and $^O ne 'VMS'); 95use constant ON_VMS => $^O eq 'VMS'; 96 97sub _list_consts { 98 my $class = shift; 99 my $pkg = shift; 100 return unless defined $pkg; # some joker might use '0' as a pkg... 101 102 my @rv; 103 { no strict 'refs'; 104 my $stash = $pkg . '::'; 105 106 for my $name (sort keys %$stash ) { 107 108 ### is it a subentry? 109 my $sub = $pkg->can( $name ); 110 next unless defined $sub; 111 112 next unless defined prototype($sub) and 113 not length prototype($sub); 114 115 push @rv, $name; 116 } 117 } 118 119 return sort @rv; 120} 121 1221; 123