File: Peek.pm

package info (click to toggle)
libarchive-peek-perl 0.37-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 104 kB
  • sloc: perl: 159; makefile: 2
file content (81 lines) | stat: -rw-r--r-- 1,679 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package Archive::Peek;
use Moo;
use Carp qw(confess);
use Archive::Peek::Tar;
use Archive::Peek::Zip;
use Types::Path::Tiny qw( File );
our $VERSION = '0.37';

has 'filename' => (
    is       => 'ro',
    isa      => File,
    required => 1,
    coerce   => 1,
);

sub BUILD {
    my $self     = shift;
    my $filename = $self->filename;
    my $basename = $filename->basename;
    if ( $basename =~ /\.zip$/i ) {
        bless $self, 'Archive::Peek::Zip';
    } elsif ( $basename =~ /(\.tar|\.tar\.gz|\.tgz|\.bz2|\.bzip2)$/i ) {
        bless $self, 'Archive::Peek::Tar';
    } else {
        confess("Failed to open $filename");
    }
}

1;

__END__

=head1 NAME

Archive::Peek - Peek into archives without extracting them

=head1 SYNOPSIS

  use Archive::Peek;
  my $peek = Archive::Peek->new( filename => 'archive.tgz' );
  my @files = $peek->files();
  my $contents = $peek->file('README.txt')
  
=head1 DESCRIPTION

This module lets you peek into archives without extracting them.
It currently supports tar files and zip files. To support Bzip2-
compressed files, you should install IO::Uncompress::Bunzip2.

=head1 METHODS

=head2 new

The constructor takes the filename of the archive to peek into:

  my $peek = Archive::Peek->new( filename => 'archive.tgz' );

=head2 files

Returns the files in the archive:

  my @files = $peek->files();

=head2 file

Returns the contents of a file in the archive:

  my $contents = $peek->file('README.txt')

=head1 AUTHOR

Leon Brocard <acme@astray.com>

=head1 COPYRIGHT

Copyright (C) 2008, Leon Brocard.

=head1 LICENSE

This module is free software; you can redistribute it or 
modify it under the same terms as Perl itself.