XML-Parser-Lite
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/XML/Parser/Lite.pm view on Meta::CPAN
# ======================================================================
#
# Copyright (C) 2000-2007 Paul Kulchenko (paulclinger@yahoo.com)
# Copyright (C) 2008 Martin Kutter (martin.kutter@fen-net.de)
# XML::Parser::Lite is free software; you can redistribute it
# and/or modify it under the same terms as Perl itself.
#
# ======================================================================
package XML::Parser::Lite;
use 5.006;
use strict;
use warnings;
our $VERSION = '0.722';
sub new {
my $class = shift;
return $class if ref $class;
my $self = bless {} => $class;
my %parameters = @_;
$self->setHandlers(); # clear first
$self->setHandlers(%{$parameters{Handlers} || {}});
return $self;
}
sub setHandlers {
my $self = shift;
# allow symbolic refs, avoid "subroutine redefined" warnings
no strict 'refs'; ## no critic
no warnings qw(redefine);
# clear all handlers if called without parameters
if (not @_) {
for (qw(Start End Char Final Init Comment Doctype XMLDecl)) {
*$_ = sub {}
}
}
# we could use each here, too...
while (@_) {
my($name, $func) = splice(@_, 0, 2);
*$name = defined $func
? $func
: sub {}
}
return $self;
}
sub _regexp {
my $patch = shift || '';
my $package = __PACKAGE__;
# This parser is based on "shallow parser" http://www.cs.sfu.ca/~cameron/REX.html
# Robert D. Cameron "REX: XML Shallow Parsing with Regular Expressions",
# Technical Report TR 1998-17, School of Computing Science, Simon Fraser University, November, 1998.
# Copyright (c) 1998, Robert D. Cameron.
# The following code may be freely used and distributed provided that
# this copyright and citation notice remains intact and that modifications
# or additions are clearly identified.
# Modifications may be tracked on XML::Parser::Lite's source code repository at
# https://github.com/redhotpenguin/perl-XML-Parser-Lite
#
use re 'eval';
my $TextSE = "[^<]+";
my $UntilHyphen = "[^-]*-";
my $Until2Hyphens = "([^-]*)-(?:[^-]$[^-]*-)*-";
#my $CommentCE = "$Until2Hyphens(?{${package}::comment(\$2)})>?";
my $CommentCE = "(.+)--(?{${package}::comment(\$2)})>?";
# my $Until2Hyphens = "$UntilHyphen(?:[^-]$UntilHyphen)*-";
# my $CommentCE = "$Until2Hyphens>?";
my $UntilRSBs = "[^\\]]*](?:[^\\]]+])*]+";
my $CDATA_CE = "$UntilRSBs(?:[^\\]>]$UntilRSBs)*>";
my $S = "[ \\n\\t\\r]+";
my $NameStrt = "[A-Za-z_:]|[^\\x00-\\x7F]";
my $NameChar = "[A-Za-z0-9_:.-]|[^\\x00-\\x7F]";
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.608 second using v1.00-cache-2.02-grep-82fe00e-cpan-cec75d87357c )