in reply to Re: Passing a Hash to another Object in MethodMaker
in thread Passing a Hash to another Object in MethodMaker

Hi Kenneth, It does seem right that I was calling it incorrectly. The above still doesn't give me what I am after ... If I change
use Class::MethodMaker [ new => "new", scalar => 'debug' , hash => '_returned_xml' , ];
to
use Class::MethodMaker [ new => "new", scalar => 'debug' , scalar => '_returned_xml' , ];
and then...
my $object = UPS::TrackedPackage->new; return $object->_returned_xml('foo'); #The set seems out of date
and with: :
my $tp = $Package->requestTrack(); #print $Package->_returned_xml(); print $tp->_returned_xml(); print Dumper($Package->_returned_xml());
I get: Can't locate object method "_returned_xml" via package "foo" (perhaps you forgot to load "foo"?) at ootrack.pl line 32. It seems there may be something I am just not getting:-) Perhaps I might have better luck with a different OO library?

Replies are listed 'Best First'.
Re^3: Passing a Hash to another Object in MethodMaker
by kennethk (Abbot) on Mar 10, 2009 at 20:37 UTC
    There are a number of very popular OO frameworks (Moose, Mouse, Class::Struct, ...). Fixing what you have here, though, should be straight forward - from Class::Method::hash:
    If a single argument is provided that is an arrayref or hashref, it is expanded and its contents used in place of the existing contents
    In other words, replace 'foo' in your code with $processedXML, you'll pass the hash and all will be well. Unless, of course, the documentation is lying.
      Hi Kenneth, Thank you for your help, the final working code is:
      my $object = UPS::TrackedPackage->new(); $object->_returned_xml($processedXML); return $object;
      and
      use Class::MethodMaker [ new => "new", scalar => 'debug' , scalar => '_returned_xml' , ];