diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2019-03-22 07:27:02 +0100 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2019-03-22 07:27:02 +0100 |
commit | dddd3e966b186f03133b91681e3aafcba9974967 (patch) | |
tree | 7b875571a212245ff7242c9dae607bcbe2124dae | |
parent | a6c49ece1afd23cc6c8ffaf05cfebaa60ccebd1a (diff) | |
download | slackbuilder-dddd3e966b186f03133b91681e3aafcba9974967.tar.gz slackbuilder-dddd3e966b186f03133b91681e3aafcba9974967.tar.bz2 |
Rewrite the extractor fabric
-rw-r--r-- | lib/SlackBuild/Archive.pm | 4 | ||||
-rw-r--r-- | lib/SlackBuild/Archive/Extractor.pm | 24 | ||||
-rw-r--r-- | lib/SlackBuild/Download.pm | 21 |
3 files changed, 21 insertions, 28 deletions
diff --git a/lib/SlackBuild/Archive.pm b/lib/SlackBuild/Archive.pm index ac6b6af..4ff241d 100644 --- a/lib/SlackBuild/Archive.pm +++ b/lib/SlackBuild/Archive.pm @@ -56,15 +56,13 @@ sub verify { sub download { croak "bad number of arguments" unless @_ == 2; my ($self, $dst) = @_; my (undef, $tmp) = tempfile(DIR => dirname($dst), UNLINK => 1); my $result = $self->SUPER::download($tmp); if ($result) { - $result = SlackBuild::Archive::Extractor - ->backend($result, $tmp, $dst) - ->extract; + $result = $result->extract($tmp, $dst); if ($result) { $self->_read_info($dst); } } return $result; } diff --git a/lib/SlackBuild/Archive/Extractor.pm b/lib/SlackBuild/Archive/Extractor.pm index de48962..15a08d1 100644 --- a/lib/SlackBuild/Archive/Extractor.pm +++ b/lib/SlackBuild/Archive/Extractor.pm @@ -1,33 +1,33 @@ package SlackBuild::Archive::Extractor; -use Carp; use SlackBuild::Archive::Extractor::HTTP; use SlackBuild::Archive::Extractor::Tar; +use Carp; sub new { croak "bad number of arguments" unless @_ == 4; - my ($class, $archive, $file, $destdir) = @_; - return bless { _archive => $archive, + my ($class, $dn, $file, $destdir) = @_; + if ($dn->isa('SlackBuild::Download')) { + if ($dn->is_html) { + return new SlackBuild::Archive::Extractor::HTTP($dn->archive, + $file, $destdir); + } else { + return new SlackBuild::Archive::Extractor::Tar($dn->archive, + $file, $destdir); + } + } + return bless { _archive => $dn, _tempfile => $file, _destdir => $destdir }, $class; } sub logger { my $self = shift; $self->{_logger} //= Log::Log4perl::get_logger(ref($self)) } -sub backend { - my ($class, $download, @args) = @_; - if ($download->is_html) { - return new SlackBuild::Archive::Extractor::HTTP($download, @args); - } else { - return new SlackBuild::Archive::Extractor::Tar($download, @args); - } -} - sub archive { shift->{_archive} } sub destdir { shift->{_destdir} } sub tempfile { shift->{_tempfile} } sub rewind { seek shift->tempfile, 0, 0 } sub extract { diff --git a/lib/SlackBuild/Download.pm b/lib/SlackBuild/Download.pm index 11af9ca..bef064b 100644 --- a/lib/SlackBuild/Download.pm +++ b/lib/SlackBuild/Download.pm @@ -1,10 +1,11 @@ package SlackBuild::Download; use strict; use warnings; use SlackBuild::Base qw(archive success content_type); +use SlackBuild::Archive::Extractor; use Carp; =head1 NAME SlackBuild::Download - download result class @@ -79,28 +80,22 @@ Return or set and return the content type (string). Return B<true> if downloaded object is an HTML page. =cut sub is_html { my $self = shift; + defined($self->content_type) + && $self->content_type =~ m{^(?:application/xhtml\+xml|text/(?:css|html))$}; } +sub extract { + my $self = shift; + SlackBuild::Archive::Extractor->new($self, @_)->extract; +} + use overload "bool" => sub { shift->success }, "0+" => sub { shift->success }, '""' => sub { shift->success ? "" : "ok" }; -our $AUTOLOAD; - -sub AUTOLOAD { - my $self = shift; - (my $name = $AUTOLOAD) =~ s/^.*:://; - if (my $method = $self->archive->can($name)) { - croak "can't apply method $name to a failed download" - unless $self->success; - return $self->archive->${\$method}(@_); - } - croak "unknown method $name in ".ref($self->archive); -} - 1; |