in reply to (raflach sample module) Re: Using Perl to create XML
in thread Using Perl to create XML

Hi raflach, I tried to use your perl but adding the OOXML module through a "require" comand inside the calling perl. It fails for : "Attempt to bless into a reference at /...OOXML.pl line 21", which is the "return bless $self, $class" line. I tried without success with the lines :
bless $self, $class; return $self
What is the problem ? Thanks Jean-michel, Nemours, FRANCE

Replies are listed 'Best First'.
Re^3: Using Perl to create XML
by jdporter (Paladin) on Apr 15, 2011 at 14:41 UTC
    What is the problem ?

    Allow me to introduce you to splain, a command-line interface to perldiag.

    C:\>splain C:\Perl\bin/splain.bat: Reading from STDIN Attempt to bless into a reference Attempt to bless into a reference (#1) (F) The CLASSNAME argument to the bless() operator is expected to +be the name of the package to bless the resulting object into. You've supplied instead a reference to something: perhaps you wrote bless $self, $proto; when you intended bless $self, ref($proto) || $proto; If you actually want to bless into the stringified version of the reference supplied, you need to stringify it yourself, for example by: bless $self, "$proto";

    So it turns out there is actually a bug in the OOXML.pm file.
    In subs new, tag, and text, he calls $self->new(...) which is precisely the trigger for the diagnostic above.
    Probably the easiest way to fix this is just to change return bless $self, $class; into return bless $self;
    That's not robust if OOXML is going to be subclassed, however. In that case, I'd recommend the following simple change instead:

    In sub new, immediately after the my( $class, ... line, insert the following line:

    $class = ref($class) if ref($class);

    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
      Hi jdporter, Using the "return bless $self" syntax, it works now ! Thank you very much. Jean-michel