Archive-Ar

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

    use Archive::Ar;

    my $ar = Archive::Ar->new;

    $ar->read('./foo.ar');
    $ar->extract;

    $ar->add_files('./bar.tar.gz', 'bat.pl')
    $ar->add_data('newfile.txt','Some contents');

    $ar->chmod('file1', 0644);
    $ar->chown('file1', $uid, $gid);

    $ar->remove('file1', 'file2');

    my $filehash = $ar->get_content('bar.tar.gz');
    my $data = $ar->get_data('bar.tar.gz');
    my $handle = $ar->get_handle('bar.tar.gz');

    my @files = $ar->list_files();

lib/Archive/Ar.pm  view on Meta::CPAN

        1;
    } || 0;
}

sub new {
    my $class = shift;
    my $file = shift;
    my $opts = shift || 0;
    my $self = bless {}, $class;
    my $defopts = {
        chmod => 1,
        chown => 1,
        same_perms => ($> == 0) ? 1:0,
        symbols => undef,
    };
    $opts = {warn => $opts} unless ref $opts;

    $self->clear();
    $self->{opts} = {(%$defopts, %{$opts})};
    if ($file) {
        return unless $self->read($file);

lib/Archive/Ar.pm  view on Meta::CPAN

    my $meta = $self->{files}->{$filename};
    return $self->_error("$filename: not in archive") unless $meta;
    open my $fh, '>', $target or return $self->_error("$target: $!");
    binmode $fh;
    syswrite $fh, $meta->{data} or return $self->_error("$filename: $!");
    close $fh or return $self->_error("$filename: $!");
    if (CAN_CHOWN && $self->{opts}->{chown}) {
        chown $meta->{uid}, $meta->{gid}, $filename or
					return $self->_error("$filename: $!");
    }
    if ($self->{opts}->{chmod}) {
        my $mode = $meta->{mode};
        unless ($self->{opts}->{same_perms}) {
            $mode &= ~(oct(7000) | (umask | 0));
        }
        chmod $mode, $filename or return $self->_error("$filename: $!");
    }
    utime $meta->{date}, $meta->{date}, $filename or
					return $self->_error("$filename: $!");
    return 1;
}

sub rename {
    my $self = shift;
    my $filename = shift;
    my $target = shift;

lib/Archive/Ar.pm  view on Meta::CPAN

        delete $self->{files}->{$filename};
        for (@{$self->{names}}) {
            if ($_ eq $filename) {
                $_ = $target;
                last;
            }
        }
    }
}

sub chmod {
    my $self = shift;
    my $filename = shift;
    my $mode = shift;	# octal string or numeric

    return unless $self->{files}->{$filename};
    $self->{files}->{$filename}->{mode} =
                                    $mode + 0 eq $mode ? $mode : oct($mode);
    return 1;
}

lib/Archive/Ar.pm  view on Meta::CPAN

    use Archive::Ar;

    my $ar = Archive::Ar->new;

    $ar->read('./foo.ar');
    $ar->extract;

    $ar->add_files('./bar.tar.gz', 'bat.pl')
    $ar->add_data('newfile.txt','Some contents');

    $ar->chmod('file1', 0644);
    $ar->chown('file1', $uid, $gid);

    $ar->remove('file1', 'file2');

    my $filehash = $ar->get_content('bar.tar.gz');
    my $data = $ar->get_data('bar.tar.gz');
    my $handle = $ar->get_handle('bar.tar.gz');

    my @files = $ar->list_files();

lib/Archive/Ar.pm  view on Meta::CPAN


Assign option $name value $val.  Possible options are:

=over 4

=item * warn

Warning level.  Levels are zero for no warnings, 1 for brief warnings,
and 2 for warnings with a stack trace.  Default is zero.

=item * chmod

Change the file permissions of files created when extracting.  Default
is true (non-zero).

=item * same_perms

When setting file permissions, use the values in the archive unchanged.
If false, removes setuid bits and applies the user's umask.  Default is
true for the root user, false otherwise.

lib/Archive/Ar.pm  view on Meta::CPAN

permissions and modification time stored in the archive, and, if possible,
the user and group ownership.  Returns non-zero upon success, or undef if
failure.

=head2 rename

  $ar->rename($filename, $newname)

Changes the name of a file in the in-memory archive.

=head2 chmod

  $ar->chmod($filename, $mode);

Change the mode of the member to C<$mode>.

=head2 chown

  $ar->chown($filename, $uid, $gid);
  $ar->chown($filename, $uid);

Change the ownership of the member to user id C<$uid> and (optionally)
group id C<$gid>.  Negative id values are ignored.

t/05_class.t  view on Meta::CPAN

can_ok $mod, 'set_opt';
can_ok $mod, 'get_opt';
can_ok $mod, 'type';
can_ok $mod, 'clear';
can_ok $mod, 'read';
can_ok $mod, 'read_memory';
can_ok $mod, 'contains_file';
can_ok $mod, 'extract';
can_ok $mod, 'extract_file';
can_ok $mod, 'rename';
can_ok $mod, 'chmod';
can_ok $mod, 'chown';
can_ok $mod, 'remove';
can_ok $mod, 'list_files';
can_ok $mod, 'add_files';
can_ok $mod, 'add_data';
can_ok $mod, 'write';
can_ok $mod, 'get_content';
can_ok $mod, 'get_data';
can_ok $mod, 'get_handle';
can_ok $mod, 'error';



( run in 0.290 second using v1.01-cache-2.11-cpan-496ff517765 )