GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Data::Path(3) User Contributed Perl Documentation Data::Path(3)

Data::Path - Perl extension for XPath like accessing from complex data structs

  use Data::Path;

  my $hashdata={
        result => {
                msg => 
                        [ { text => 'msg0' }
                        , { text => 'msg1' }
                        , { text => 'msg2' }
                        ]
        },
    method => sub {'method text'}
  }
  
  my $hpath=Data::Path->new($hashdata);
  my $value= $hpath->get('/result/msg[1]/text');
  my $value2 = $hpath->get('/method()');
  
  print "OK" if $value2 eq 'method text';
  print "OK" if $value eq 'msg1';


  my $hpath=Data::Path->new($hashdata,$callback);

  my $hpath=Data::Path->new
        ($hashdata,
        { key_does_not_exist => sub { die index not found } 
        );

XPath like access to get values from a complex data structs.

key_does_not_exist / index_does_not_exist are only called if it was not the last part of the path. If the last part of path is not exists undef is returned.

The default callbacks but you can overwrite this.

        { key_does_not_exist            =>
                sub {
                        my ($data, $key, $index, $value, $rest )=@_;
                        croak "key $key does not exists\n";
                }

        , index_does_not_exist         =>
                sub {
                        my ($data, $key, $index, $value, $rest )=@_;
                        croak "key $key\[$index\] does not exists\n";
                }

        , retrieve_index_from_non_array =>
                sub {
                        my ($data, $key, $index, $value, $rest )=@_;
                        croak "trie to retrieve an index $index from a no array value (in key $key)\n";
                }

        , retrieve_key_from_non_hash    =>
                sub {
                        my ($data, $key, $index, $value, $rest )=@_;
                        croak "trie to retrieve a key from a no hash value (in key $key)\n";
                }
        , not_a_coderef_or_method    => $callback->{not_a_coderef_or_method} ||
                sub {
                        my ($data, $key, $index, $value, $rest )=@_;
                        croak "tried to retrieve from a non-existant coderef or method";
                }
        }

  my $hpath=Data::Path->new
        ($hashdata,
        { key_does_not_exist   => sub { die key not found } 
        { index_does_not_exist => sub { die index not found } 
        );

None by default.

        XPath

Slices of data through /foo[*]/bar syntax. eg. retrieve all the bar keys from each element of the foo array.

allow accessing the results of coderefs eg. /foo()/bar retreive the result of the foo coderef/method of the object

Marco Schrieck, <marco.schrieck@gmx.de>

Jeremy Wall jeremy@marzhillstudios.com

Copyright (C) 2006 by Marco Schrieck Copyright (C) 2007 by Jeremy Wall

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.

2008-02-27 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.