PLJava
view release on metacpan or search on metacpan
basiclib/XML/Smart.pm-txt view on Meta::CPAN
@{$$pointer{'/order'}} = @_ ;
}
sub order {
my $this = shift ;
my $pointer = $$this->{point} ;
return @{$$pointer{'/order'}} if defined $$pointer{'/order'} && ref($$pointer{'/order'}) eq 'ARRAY' ;
return() ;
}
#############
# SET_CDATA #
#############
sub set_node_type {
my $this = shift ;
my ( $type , $bool ) = @_ ;
if ( $#_ < 1 ) { $bool = 1 ;}
my $key = $this->key ;
my $back = $this->back ;
$back->{'/nodes'} = {} if $back->{'/nodes'}->null ;
my $nodes = $back->{'/nodes'}->pointer ;
if ( $bool ) {
if ( $$nodes{$key} =~ /^\w+,\d+,(\d*)/ ) {
my $val = $1 ;
$$nodes{$key} = "$type,1,$val" ;
}
else { $$nodes{$key} = "$type,1,$$nodes{$key}" ;}
if ( !$this->{CONTENT} ) {
my $content = $this->content ;
$this->{CONTENT} = $content if $content ne '' ;
}
}
else {
if ( !$$nodes{$key} ) {
my $tp = _data_type( $back->{$key} ) ;
if ( $tp > 2 ) { $$nodes{$key} = "$type,0," ;}
}
elsif ( $$nodes{$key} eq '1' ) { $$nodes{$key} = "$type,0,1" ;}
elsif ( $$nodes{$key} =~ /^\w+,\d+,1/ ) { $$nodes{$key} = "$type,0,1" ;}
elsif ( $$nodes{$key} =~ /^\w+,\d+,0?$/ ) {
delete $$nodes{$key} ;
my @keys = keys %$this ;
if ( $#keys == 0 && @keys[0] eq 'CONTENT') {
my $content = $this->{CONTENT}('.') ;
$this->back->pointer->{$key} = $content ;
}
}
}
}
#############
# SET_CDATA #
#############
sub set_cdata {
my $this = shift ;
$this->set_node_type('cdata',@_) ;
}
##############
# SET_BINARY #
##############
sub set_binary {
my $this = shift ;
$this->set_node_type('binary',@_) ;
}
#################
# SET_AUTO_NODE #
#################
sub set_auto_node {
my $this = shift ;
my $key = $this->key ;
my $back = $this->back ;
$back->{'/nodes'} = {} if $back->{'/nodes'}->null ;
my $nodes = $back->{'/nodes'}->pointer ;
if ( !$$nodes{$key} || $$nodes{$key} eq '1' ) { ; }
elsif ( $$nodes{$key} =~ /^\w+,\d+,1/ ) { $$nodes{$key} = 1 ;}
elsif ( $$nodes{$key} =~ /^\w+,\d+,0?$/ ) {
delete $$nodes{$key} ;
my @keys = keys %$this ;
if ( $#keys == 0 && @keys[0] eq 'CONTENT') {
my $content = $this->{CONTENT}('.') ;
$this->back->pointer->{$key} = $content ;
}
}
}
############
# SET_AUTO #
############
sub set_auto {
my $this = shift ;
my $key = $this->key ;
my $back = $this->back ;
$back->{'/nodes'} = {} if $back->{'/nodes'}->null ;
my $nodes = $back->{'/nodes'}->pointer ;
delete $$nodes{$key} ;
my @keys = keys %$this ;
if ( $#keys == 0 && @keys[0] eq 'CONTENT') {
my $content = $this->{CONTENT}('.') ;
$this->back->pointer->{$key} = $content ;
}
}
##############
# _DATA_TYPE #
##############
basiclib/XML/Smart.pm-txt view on Meta::CPAN
Return the key of the value.
If wantarray return the index too: return(KEY , I) ;
=head2 nodes()
Return the nodes (objects) in the pointer (keys that aren't arguments).
=head2 nodes_keys()
Return the nodes names (not the object) in the pointer (keys that aren't arguments).
=head2 null()
Return I<true> if the XML object has a null tree or if the pointer is in some place that doesn't exist.
=head2 order()
Return the order of the keys. See I<set_order()>.
=head2 path()
Return the path of the pointer.
I<Example>:
/hosts/server[1]/address[0]
B<Note that the index is 0 based and 'address' can be an attribute or a node, what is not compatible with XPath.>
B<** See I<path_as_xpath()>.>
=head2 path_as_xpath()
Return the path of the pointer in the XPath format.
=head2 pointer
Return the HASH tree from the pointer.
=head2 pointer_ok
Return a copy of the tree of the object, B<from the pointer>, but without internal keys added by I<XML::Smart>.
=head2 root
Return the ROOT name of the XML tree (main key).
** See also I<key()> for sub nodes.
=head2 save (FILEPATH , OPTIONS)
Save the XML data inside a file.
Accept the same OPTIONS of the method B<I<data()>>.
=head2 set_auto
Define the key to be handled automatically. Soo, data() will define automatically if it's a node, content or attribute.
I<** This method is useful to remove set_node(), set_cdata() and set_binary() changes.>
=head2 set_auto_node
Define the key as a node, and data() will define automatically if it's CDATA or BINARY.
I<** This method is useful to remove set_cdata() and set_binary() changes.>
=head2 set_binary(BOOL)
Define the node as a BINARY content when TRUE, or force to B<not> handle it as a BINARY on FALSE.
Example of node handled as BINARY:
<root><foo dt:dt="binary.base64">PGgxPnRlc3QgAzwvaDE+</foo></root>
Original content of foo (the base64 data):
<h1>test \x03</h1>
=head2 set_cdata(BOOL)
Define the node as CDATA when TRUE, or force to B<not> handle it as CDATA on FALSE.
Example of CDATA node:
<root><foo><![CDATA[bla bla bla <tag> bla bla]]></foo></root>
=head2 set_node(BOOL)
Set/unset the current key as a node (tag).
** If BOOL is not defined will use I<TRUE>.
=head2 set_order(KEYS)
Set the order of the keys (nodes and attributes) in this point.
=head2 set_tag
Same as set_node.
=head2 tree()
Return the HASH tree of the XML data.
** Note that the real HASH tree is returned here. All the other ways return an
object that works like a HASH/ARRAY through tie.
=head2 tree_pointer()
Same as I<pointer()>.
=head2 tree_ok()
Return a copy of the tree of the object, but without internal keys added by I<XML::Smart>, like I</order> and I</nodes>.
=head2 tree_pointer_ok()
Return a copy of the tree of the object, B<from the pointer>, but without internal keys added by I<XML::Smart>.
=head2 xpath() || XPath()
Return a XML::XPath object, based in the XML root in the tree.
## look from the root:
my $data = $XML->XPath->findnodes_as_string('/') ;
I<** Need XML::XPath installed, but only load when is needed.>
=head2 xpath_pointer() || XPath_pointer()
Return a XML::XPath object, based in the XML::Smart pointer in the tree.
## look from this point, soo XPath '/' actually starts at /server/:
my $srvs = $XML->{server} ;
my $data = $srvs->XPath_pointer->findnodes_as_string('/') ;
I<** Need XML::XPath installed, but only load when is needed.>
( run in 0.579 second using v1.01-cache-2.11-cpan-fa01517f264 )