Why?
Is not because I can, is because I need. ;-P

Is for a XML module that need to work in the same time in different ways. For example, in XML::Simple you have a hash tree, where inside it you have some parts that are ARRAY ref, soo you need to know when you have an ARRAY and a HASH to access the data, or you need to configure the parser to force the ARRAY to always have an ARRAY on unique points.

With my idea you can just work directly with the HASH or ARRAY to get the data, make a search, etc... All using the basic Perl syntax for HASH, ARRAY, CODE & SCALAR.

Here's an example of how you can access the data:

my $addr = $xml->{config}{server}->('name','=~','sahara')->{address} +[0] ; ## the same, it just get the first: my $addr = $xml->{config}{server}->('name','=~','sahara')->{address} + ; ## return all the addresses: my @addrs = $xml->{config}{server}->('name','=~','sahara')->{address +} ; ## Get the first server node: my $server = $xml->{config}{server}[0] ; ## or without [0], since wihtout always return the 1st: my $server = $xml->{config}{server} ; ## Or get the server that have a specific name, ## when you don't know the order: my $server = $xml->{config}{server}->('name','eq','sahara') ; my $addr = $server->{address} ; ## Print the content: print "Server content: $server\n" ; __DATA__ <config logdir="/var/log/foo/" debugfile="/tmp/foo.debug"> <server name="sahara" osname="solaris" osversion="2.6"> <address>10.0.0.101</address> <address>10.0.1.101</address> </server> <server name="gobi" osname="irix" osversion="6.5"> <address>10.0.0.102</address> </server> <server name="kalahari" osname="linux" osversion="2.0.34"> <address>10.0.0.103</address> <address>10.0.1.103</address> </server> </config>
Note that this styles to get the data are still in plan stage. I'm just finishing the Object::MultiType module to see all the resources that I have to do that... But the styles above are already supported! ;-P

Graciliano M. P.
"The creativity is the expression of the liberty".


In reply to Re: &bull;Re: Object::MultiType - Perl Objects as Hash, Array & Scalar in the same time! by gmpassos
in thread Object::MultiType - Perl Objects as Hash, Array & Scalar in the same time! by gmpassos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.