summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2019-03-22 06:27:02 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2019-03-22 06:27:02 (GMT)
commitdddd3e966b186f03133b91681e3aafcba9974967 (patch) (side-by-side diff)
tree7b875571a212245ff7242c9dae607bcbe2124dae
parenta6c49ece1afd23cc6c8ffaf05cfebaa60ccebd1a (diff)
downloadslackbuilder-dddd3e966b186f03133b91681e3aafcba9974967.tar.gz
slackbuilder-dddd3e966b186f03133b91681e3aafcba9974967.tar.bz2
Rewrite the extractor fabric
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/SlackBuild/Archive.pm4
-rw-r--r--lib/SlackBuild/Archive/Extractor.pm24
-rw-r--r--lib/SlackBuild/Download.pm21
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
@@ -59,9 +59,7 @@ sub download {
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);
}
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,12 +1,21 @@
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;
}
@@ -16,15 +25,6 @@ sub logger {
$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} }
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
@@ -2,6 +2,7 @@ package SlackBuild::Download;
use strict;
use warnings;
use SlackBuild::Base qw(archive success content_type);
+use SlackBuild::Archive::Extractor;
use Carp;
=head1 NAME
@@ -82,25 +83,19 @@ Return B<true> if downloaded object is an HTML page.
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;

Return to:

Send suggestions and report system problems to the System administrator.