NAME
Parse::FieldPath
ABSTRACT
Parses an XPath inspired field list and extracts those fields from an object hierarchy.
Based on the "fields" parameter for the Google+ API: http://developers.google.com/+/api/
SYNOPSIS
Say you have an object, with some sub-objects, that's initialized like this:
my $cow = Cow->new();
$cow->color("black and white");
$cow->tail(Cow::Tail->new(floppy => 1));
$cow->mouth(Cow::Tounge->new(
tounge => Cow::Tounge->new,
teeth => Cow::Teeth->new,
);
And you want a hash containing some of those fields (perhaps to pass to JSON::XS, or something). Then you can do this:
use Parse::FieldPath qw/extract_fields/;
my $cow_hash = extract_fields($cow, "color,tail/floppy");
# $cow_hash is now:
# {
# color => 'black and white',
# tail => {
# floppy => 1,
# }
# }
SYNTAX
(To be written)
FUNCTIONS
- extract_fields ($object, $field_path)
-
Parses the field_path and returns the fields requested from $object.
- build_tree ($field_path)
-
Parses the field_path and returns a tree structure describing it.
BUGS / LIMITATIONS
- Doesn't support arrays currently
- Needs more callbacks
- Assumes that objects are blessed hashrefs (which isn't necessarily true)
- "field/*" doesn't work very well at present
AUTHOR
Paul Boyd <pboyd@dev3l.net>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Paul Boyd.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.