Mac-PropertyList-SAX
view release on metacpan or search on metacpan
lib/Mac/PropertyList/SAX.pm view on Meta::CPAN
select a parser capable of doing the heavy lifting, reducing parsing time on
large files by a factor of 30 or more.
This module does not replace L<Mac::PropertyList|Mac::PropertyList>: it depends
on it for some package definitions and plist printing routines. You should,
however, be able to replace all C<use Mac::PropertyList>
lines with C<use Mac::PropertyList::SAX>, without changing anything else, and
notice an immediate improvement in performance on large input files.
Performance will depend largely on the parser that
L<XML::SAX::ParserFactory|XML::SAX::ParserFactory> selects for you. By default,
L<XML::SAX::Expat|XML::SAX::Expat> is used; to change the parser used, set the
environment variable C<MAC_PROPERTYLIST_SAX_PARSER> to a value accepted by
$XML::SAX::ParserPackage from
L<XML::SAX::ParserFactory|XML::SAX::ParserFactory> (or set
C<$XML::SAX::ParserPackage> directly).
=cut
use strict;
use warnings;
use HTML::Entities qw(encode_entities_numeric);
use HTML::Entities::Numbered qw(hex2name name2hex_xml);
# Passthrough function
use Mac::PropertyList qw(plist_as_string);
use XML::SAX::ParserFactory;
use base qw(Exporter);
our @EXPORT_OK = qw(
parse_plist
parse_plist_fh
parse_plist_file
parse_plist_string
plist_as_string
create_from_ref
create_from_hash
create_from_array
create_from_string
);
our %EXPORT_TAGS = (
all => \@EXPORT_OK,
create => [ qw(create_from_ref create_from_hash create_from_array create_from_string plist_as_string) ],
parse => [ qw(parse_plist parse_plist_fh parse_plist_file parse_plist_string) ],
);
our $VERSION = '1.002';
=head1 CLASS VARIABLES
Class scoped variables that control the packages settings.
=over 4
=item ENCODE_ENTITIES
Allows the XHTML encoding of the data to be turned off. Default = C<1>
=item ENCODE_UNSAFE_CHARS
A Perl character class definition containing the only characters to be
XHTML encoded. See HTML::Entities::encode_entities for description of
the $unsafe_chars parameter. Default = C<undef>
=cut
our $ENCODE_ENTITIES = 1;
our $ENCODE_UNSAFE_CHARS = undef;
=item OLD_BEHAVIOR
Restores the old behavior of double encoding output data. Default = C<0>
=cut
our $OLD_BEHAVIOR = 0;
=item XML::SAX::ParserPackage
Parser to use. Can also be set with environment variable
C<MAC_PROPERTYLIST_SAX_PARSER>. Default = C<"XML::SAX::Expat">
=cut
$XML::SAX::ParserPackage = $ENV{MAC_PROPERTYLIST_SAX_PARSER} || "XML::SAX::Expat";
=back
=head1 EXPORTS
By default, no functions are exported. Specify individual functions to export
as usual, or use the tags ':all', ':create', and ':parse' for the appropriate
sets of functions (':create' includes the create* functions as well as
plist_as_string; ':parse' includes the parse* functions).
=head1 FUNCTIONS
=over 4
=item parse_plist_file
See L<Mac::PropertyList/parse_plist_file>
=cut
sub parse_plist_file {
my $file = shift;
if (ref $file) {
parse_plist_fh($file);
} else {
die "parse_plist_file: file [$file] does not exist!" unless -e $file;
_parse("parse_uri", $file);
}
}
=item parse_plist_fh
See L<Mac::PropertyList/parse_plist_fh>
=cut
( run in 2.265 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )