Why not adopt me?
NAME
Mac::PropertyListFilter - Transform XML Property lists into data structure.
SYNOPSIS
use Mac::PropertyList;
use Mac::PropertyListFilter qw(xml_filter);
$data = Mac::PropertyList::parse_plist($string);
$funcref = [
#
# Transform { a=>1,w=>0.6 } to [1,0.6]
#
sub {
my $color = shift;
if(ref($color) eq 'HASH' and
defined $color->{a} and
defined $color->{w}) {
}
}
];
$new_data = xml_filter($data,$funcref);
DESCRIPTION
The filter transforms the output of parse_plist() to a more sensible form. Generally, type =
'dict', value => { }> gets transformed to a simple hashref, type =
'array', value => [ ]> gets transformed to an array ref. This transformation will lose data, specifically it retains no type information from the original XML. type =
'real'> gets lost in the shuffle, however this may not be useful to your application, or even misleading.
OmniGraffle 2.0, for instance, uses a string type to represent points, booleans and rectangles. In addition to reshaping the output in this fashion, this lets you transform hashrefs into arrayrefs.
The second parameter to xml_filter() is an arrayref of references to functions. The functions get called in order on every hash and array reference, and element, depth-first. If the function returns any data, it replaces what was there before.
As such, the xml_filter does not actually modify the data structure, unless your subroutines modify data. This can be useful, especially when transforming the OmniGraffle representation of a point "{32, 27}"
into something easier to deal with, such as [32,27]
.
EXPORT
None by default, xml_parser()
on request.
SEE ALSO
Mac::PropertyList, http://www.apple.com/DTDs/PropertyList-1.0.dtd
AUTHOR
Jeffrey Goff, <jgoff@cpan.org>
COPYRIGHT AND LICENSE
Copyright 2004 by Jeffrey Goff
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.