Skip Menu |

This queue is for tickets about the File-Fetch CPAN distribution.

Report information
The Basics
Id: 53427
Status: resolved
Worked: 10 min
Priority: 0/
Queue: File-Fetch

People
Owner: BINGOS [...] cpan.org
Requestors: bdfoy [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: File::Fetch new does not respect subclasses.
 In new(), File::Fetch uses __PACKAGE__ and a literal 'File::Fetch' to create the object and does not rebless the object into $class. There are many ways you could go with a fix, but the simplest is probably just to rebless $ff before you return it.
Here's a possible patch with tests.

Subject: 0001--Allow-File-Fetch-subclasses.patch
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
Thanks, patch applied and new version shipped to CPAN

Changes for 0.24        Wed Jan  6 23:32:19 2010
=================================================
* Applied a patch from brian d foy RT #53427
  that makes new() respect sub-classes.