From: Grant M. <gr...@us...> - 2006-10-29 07:28:28
|
Update of /cvsroot/perl-xml/xml-simple/lib/XML In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22921/lib/XML Modified Files: Simple.pm Log Message: - refactoring of code to turn function calls into method calls Index: Simple.pm =================================================================== RCS file: /cvsroot/perl-xml/xml-simple/lib/XML/Simple.pm,v retrieving revision 1.32 retrieving revision 1.33 diff -u -d -r1.32 -r1.33 --- Simple.pm 29 Oct 2006 07:09:39 -0000 1.32 +++ Simple.pm 29 Oct 2006 07:28:25 -0000 1.33 @@ -130,20 +130,13 @@ ############################################################################## -# Sub/Method: XMLin() -# -# Exported routine for slurping XML into a hashref - see pod for info. -# -# May be called as object method or as a plain function. +# Sub: _get_object() # -# Expects one arg for the source XML, optionally followed by a number of -# name => value option pairs. +# Helper routine called from XMLin() and XMLout() to create an object if none +# was provided. Note, this routine does mess with the caller's @_ array. # -sub XMLin { - - # If this is not a method call, create an object - +sub _get_object { my $self; if($_[0] and UNIVERSAL::isa($_[0], 'XML::Simple')) { $self = shift; @@ -151,7 +144,23 @@ else { $self = XML::Simple->new(); } + + return $self; +} + +############################################################################## +# Sub/Method: XMLin() +# +# Exported routine for slurping XML into a hashref - see pod for info. +# +# May be called as object method or as a plain function. +# +# Expects one arg for the source XML, optionally followed by a number of +# name => value option pairs. +# +sub XMLin { + my $self = &_get_object; # note, @_ is passed implicitly my $string = shift; @@ -482,16 +491,7 @@ # sub XMLout { - - # If this is not a method call, create an object - - my $self; - if($_[0] and UNIVERSAL::isa($_[0], 'XML::Simple')) { - $self = shift; - } - else { - $self = XML::Simple->new(); - } + my $self = &_get_object; # note, @_ is passed implicitly croak "XMLout() requires at least one argument" unless(@_); my $ref = shift; |