Subject: | Suggestion: make 'parse' and 'parsefile' methods to be callable as class methods |
Hi guys!
It would be convenient to make 'parse' and 'parsefile' methods
to be callable as class methods.
Say, I want to parse RSS file. I have to do something like this.
my $rss = XML::RSS->new();
$rss->parsefile('file.rss');
It would be handy to do one action instead of two.
my $rss = XML::RSS->parsefile('file.rss');
There is one issue. Now both methods return RSS version number.
This behavior isn't documented and seems to be a side effect of
internal version assignment so I guess it would be nice to always
return $self.
Patch is attached.
Of course it doesn't break backwards compatibility.
Subject: | RSS.pm.diff |
Index: libxml-rss-perl/lib/XML/RSS.pm
===================================================================
--- libxml-rss-perl/lib/XML/RSS.pm (revision 11067)
+++ libxml-rss-perl/lib/XML/RSS.pm (working copy)
@@ -976,6 +976,8 @@
my $self = shift;
my $text_to_parse = shift;
+ $self = $self->new() unless ref $self;
+
$self->_reset;
# Workaround to make sure that if we were defined with version => "2.0"
@@ -988,11 +990,15 @@
$self->_auto_add_modules if $AUTO_ADD;
$self->{version} = $self->{_internal}->{version};
+
+ return $self;
}
sub parsefile {
my $self = shift;
+ $self = $self->new() unless ref $self;
+
$self->_reset;
# Workaround to make sure that if we were defined with version => "2.0"
@@ -1005,6 +1011,8 @@
$self->_auto_add_modules if $AUTO_ADD;
$self->{version} = $self->{_internal}->{version};
+
+ return $self;
}
# Check if Perl supports the :encoding layer in File I/O.