in reply to Re^3: Object as Moose Object attribute
in thread Object as Moose Object attribute

Thanks, By the way what is better for this case Ref or hashRef ? And why ?

Replies are listed 'Best First'.
Re^5: Object as Moose Object attribute
by Your Mother (Archbishop) on Nov 02, 2015 at 20:46 UTC

    Oh, well, whatever you want, as specifically as you expect is what to do. If the XMLin() will always return a HashRef for your data, then specify that. Otherwise something like \my $moo; can be considered valid XML in your object layer. Better to catch problems early. I think you can | (OR) stuff together too if you need to consider ArrayRef as well. I'm not even sure if XML::Simple allows for that. While we're on the topic XML::Simple is not really anyone's friend except in the most predictable and unchanging use. See Examples where XML::Simple is the optimal choice? and Stepping up from XML::Simple to XML::LibXML.

      Thanks a lot for precisions and advices !!! I appreciate ! I really do.

        You are doing it right. Asking easy, bite-sized questions will tend to you get you high quality answers quickly here. They're more fun as is polite interaction. Therefore, you are very welcome! :P

Re^5: Object as Moose Object attribute
by Anonymous Monk on Nov 02, 2015 at 20:49 UTC

    That depends a bit on what your XML looks like - XMLin will usually return a hashref, but there is some XML that will cause it to return an arrayref. So if you wanted to play it safe you could say isa => 'HashRef | ArrayRef', or if you know your XML will always look a certain way and so XMLin will always return a hashref, just say isa => 'HashRef', which should make the rest of your code easier because it doesn't have to check every time if it's a hashref or arrayref. Ref is a superset that includes a whole lot more than hashrefs and arrayrefs, so it's probably too general. For all the details see Moose::Manual::Types. By the way, XML::Simple is not really recommended for new code, see for example this thread.

    (Update: Your Mother already replied as I was typing, so yeah :-) )

      As our answers are essentially identical, I heartily endorse yours! Sychronicity intentsifies…

      Thanks a lot, both of you !