Mac::PropertyListFilter - Transform XML Property lists into data structure.
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);
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.
type =
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].
"{32, 27}"
[32,27]
None by default, xml_parser() on request.
xml_parser()
Mac::PropertyList, http://www.apple.com/DTDs/PropertyList-1.0.dtd
Jeffrey Goff, <jgoff@cpan.org>
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.
To install Mac::PropertyListFilter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mac::PropertyListFilter
CPAN shell
perl -MCPAN -e shell install Mac::PropertyListFilter
For more information on module installation, please visit the detailed CPAN module installation guide.