From f37e28a24167a460d53d2563afdb1f97e6d4963e Mon Sep 17 00:00:00 2001
From: brian d foy <brian.d.foy@gmail.com>
Date: Wed, 6 Jan 2010 15:03:25 +0100
Subject: [PATCH] * Allow File::Fetch subclasses
---
.gitignore | 3 +++
lib/File/Fetch.pm | 8 ++++----
t/null_subclass.t | 23 +++++++++++++++++++++++
3 files changed, 30 insertions(+), 4 deletions(-)
create mode 100644 .gitignore
create mode 100644 t/null_subclass.t
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0b5bd39
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+Makefile
+blib
+pm_to_blib
diff --git a/lib/File/Fetch.pm b/lib/File/Fetch.pm
index d90232f..6a1c3c8 100644
--- a/lib/File/Fetch.pm
+++ b/lib/File/Fetch.pm
@@ -178,13 +178,13 @@ result of $ff->output_file will be used.
bless $args, $class;
if( lc($args->scheme) ne 'file' and not $args->host ) {
- return File::Fetch->_error(loc(
+ return $class->_error(loc(
"Hostname required when fetching from '%1'",$args->scheme));
}
for (qw[path file]) {
unless( $args->$_() ) { # 5.5.x needs the ()
- return File::Fetch->_error(loc("No '%1' specified",$_));
+ return $class->_error(loc("No '%1' specified",$_));
}
}
@@ -275,10 +275,10 @@ sub new {
check( $tmpl, \%hash ) or return;
### parse the uri to usable parts ###
- my $href = __PACKAGE__->_parse_uri( $uri ) or return;
+ my $href = $class->_parse_uri( $uri ) or return;
### make it into a FFI object ###
- my $ff = File::Fetch->_create( %$href ) or return;
+ my $ff = $class->_create( %$href ) or return;
### return the object ###
diff --git a/t/null_subclass.t b/t/null_subclass.t
new file mode 100644
index 0000000..7c68854
--- /dev/null
+++ b/t/null_subclass.t
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+
+my $parent_class = 'File::Fetch';
+my $child_class = 'File::Fetch::Subclass';
+
+use_ok( $parent_class );
+
+my $ff_parent = $parent_class->new( uri => '
http://example.com/index.html' );
+isa_ok( $ff_parent, $parent_class );
+
+can_ok( $child_class, qw( new fetch ) );
+my $ff_child = $child_class->new( uri => '
http://example.com/index.html' );
+isa_ok( $ff_child, $child_class );
+isa_ok( $ff_child, $parent_class );
+
+BEGIN {
+ package File::Fetch::Subclass;
+ use vars qw(@ISA);
+ unshift @ISA, qw(File::Fetch);
+ }
--
1.6.2.5