libxml-perl
view release on metacpan or search on metacpan
<foo>&anEntRef;</foo>
EOF;
eval {
$parser->parse( Source => { String => $xmlstring },
Handler => NoEntRefsHandler->new( Tests => \@tests ) );
};
warn $@ if $@;
eval {
$parser->parse( Source => { String => $xmlstring },
Handler => EntRefsHandler->new( Tests => \@tests ) );
};
warn $@ if $@;
for (3 .. 15)
{
print "not " unless $tests[$_];
print "ok $_\n";
}
exit;
package TestHandler;
sub new {
my $type = shift;
return bless { @_ }, $type;
}
sub characters {
my $self = shift;
$self->{Tests}[4] ++;
}
sub start_element {
my $self = shift;
$self->{Tests}[5] ++;
}
sub end_element {
my $self = shift;
$self->{Tests}[6] ++;
}
sub processing_instruction {
my $self = shift;
$self->{Tests}[7] ++;
}
sub notation_decl {
my $self = shift;
$self->{Tests}[8] ++;
}
sub unparsed_entity_decl {
my $self = shift;
$self->{Tests}[9] ++;
}
sub start_cdata {
my $self = shift;
$self->{Tests}[12] ++;
}
sub end_cdata {
my $self = shift;
$self->{Tests}[13] ++;
}
sub resolve_entity {
my $self = shift;
my $entity = shift;
if ($entity->{SystemId} eq 'fran-def') {
$self->{Tests}[10] ++;
return { String => 'pretty' };
} elsif ($entity->{SystemId} eq 'zoe.ent') {
$self->{Tests}[11] ++;
local(*FOO);
open(FOO, $entity->{SystemId}) or die "Couldn't open $entity->{SystemId}";
return { ByteStream => *FOO };
}
}
package NoEntRefsHandler;
sub new {
my $type = shift;
return bless { @_ }, $type;
}
sub characters {
my $self = shift;
my $characters = shift;
if ($characters->{Data} eq 'The Ent Ref') {
$self->{Tests}[14] ++;
}
}
package EntRefsHandler;
sub new {
my $type = shift;
return bless { @_ }, $type;
}
sub characters {
my $self = shift;
my $characters = shift;
if ($characters->{Data} eq 'The Ent Ref') {
die "shouldn't have made it here";
}
}
sub entity_reference {
my $self = shift;
my $ent_ref = shift;
if (($ent_ref->{Name} eq 'anEntRef')
&& ($ent_ref->{Value} eq 'The Ent Ref')) {
$self->{Tests}[15] ++;
}
}
( run in 0.367 second using v1.01-cache-2.11-cpan-140bd7fdf52 )