| 1 | package DJabberd::TestSAXHandler; | ||||||||||||||||||||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use base qw(XML::SAX::Base); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use DJabberd::SAXHandler; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 20 | ▶ | use DJabberd::XMLElement; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use DJabberd::StreamStart; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 883 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 883 | my ($class, $listref) = @_; | |||||||||||||||||||||||||||
| 10 | 883 | my $self = $class->SUPER::new; | |||||||||||||||||||||||||||
| 11 | 883 | $self->{"listref"} = $listref; | |||||||||||||||||||||||||||
| 12 | 883 | $self->{"capture_depth"} = 0; # on transition from 1 to 0, stop capturing | |||||||||||||||||||||||||||
| 13 | 883 | $self->{"on_end_capture"} = undef; # undef or $subref->($doc) | |||||||||||||||||||||||||||
| 14 | 883 | $self->{"events"} = []; # capturing events | |||||||||||||||||||||||||||
| 15 | 883 | return $self; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 20 | ▶ | use constant EVT_START_ELEMENT => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 20 | ▶ | use constant EVT_END_ELEMENT => 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 20 | ▶ | use constant EVT_CHARS => 3; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1609 | ▶ | sub start_element { | ||||||||||||||||||||||||||
|
Subroutine
start_element: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 1609 | my $self = shift; | |||||||||||||||||||||||||||
| 24 | 1609 | my $data = shift; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1609 | ▶ | if ($self->{capture_depth}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 405 | push @{$self->{events}}, [EVT_START_ELEMENT, $data]; | |||||||||||||||||||||||||||
| 28 | 405 | $self->{capture_depth}++; | |||||||||||||||||||||||||||
| 29 | 405 | return; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1204 | ▶ | if ($data->{LocalName} eq "djab-noop") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | return; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # {=xml-stream} | ||||||||||||||||||||||||||||
| 37 | 1204 | ▶ | if ($data->{NamespaceURI} eq "http://etherx.jabber.org/streams" && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$data->{"NamespaceURI"} eq "http://etherx.jabber.org/streams" and $data->{"LocalName"} eq "stream"
MC/DC100%2/2
$data->{"NamespaceURI"} eq "http://etherx.jabber.org/streams" and $data->{"LocalName"} eq "stream"
$data->{"NamespaceURI"} eq "http://etherx.jabber.org/streams"
$data->{"LocalName"} eq "stream"
Truth table100%3/3
A and B
A= $data->{"NamespaceURI"} eq "http://etherx.jabber.org/streams"B= $data->{"LocalName"} eq "stream"
| |||||||||||||||||||||||||||||
| 38 | $data->{LocalName} eq "stream") { | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 883 | my $ss = DJabberd::StreamStart->new($data); | |||||||||||||||||||||||||||
| 41 | 883 | push @{$self->{listref}}, $ss; | |||||||||||||||||||||||||||
| 42 | 883 | return; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 321 | ▶ | my $start_capturing = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 321 | my $cb = shift; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 321 | $self->{"events"} = []; # capturing events | |||||||||||||||||||||||||||
| 49 | 321 | $self->{capture_depth} = 1; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # capture via saving SAX events | ||||||||||||||||||||||||||||
| 52 | 321 | push @{$self->{events}}, [EVT_START_ELEMENT, $data]; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 321 | $self->{on_end_capture} = $cb; | |||||||||||||||||||||||||||
| 55 | 321 | return 1; | |||||||||||||||||||||||||||
| 56 | 321 | }; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 321 | ▶ | return $start_capturing->(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 321 | my ($doc, $events) = @_; | |||||||||||||||||||||||||||
| 60 | 321 | my $nodes = _nodes_from_events($events); | |||||||||||||||||||||||||||
| 61 | # {=xml-stanza} | ||||||||||||||||||||||||||||
| 62 | 321 | push @{$self->{listref}}, $nodes->[0]; | |||||||||||||||||||||||||||
| 63 | 321 | }); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 115 | ▶ | sub characters { | ||||||||||||||||||||||||||
|
Subroutine
characters: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 115 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 115 | ▶ | if ($self->{capture_depth}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 115 | push @{$self->{events}}, [EVT_CHARS, $data]; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 728 | ▶ | sub end_element { | ||||||||||||||||||||||||||
|
Subroutine
end_element: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 728 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 728 | ▶ | if ($data->{NamespaceURI} eq "http://etherx.jabber.org/streams" && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$data->{"NamespaceURI"} eq "http://etherx.jabber.org/streams" and $data->{"LocalName"} eq "stream"
MC/DC100%2/2
$data->{"NamespaceURI"} eq "http://etherx.jabber.org/streams" and $data->{"LocalName"} eq "stream"
$data->{"NamespaceURI"} eq "http://etherx.jabber.org/streams"
$data->{"LocalName"} eq "stream"
Truth table100%3/3
A and B
A= $data->{"NamespaceURI"} eq "http://etherx.jabber.org/streams"B= $data->{"LocalName"} eq "stream"
| |||||||||||||||||||||||||||||
| 79 | $data->{LocalName} eq "stream") { | ||||||||||||||||||||||||||||
| 80 | 2 | push @{$self->{listref}}, "end-stream"; | |||||||||||||||||||||||||||
| 81 | 2 | return; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 726 | ▶ | if ($self->{capture_depth}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 726 | push @{$self->{events}}, [EVT_END_ELEMENT, $data]; | |||||||||||||||||||||||||||
| 86 | 726 | $self->{capture_depth}--; | |||||||||||||||||||||||||||
| 87 | 726 | ▶ | return if $self->{capture_depth}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 321 | my $doc = undef; | |||||||||||||||||||||||||||
| 89 | 321 | ▶ | if (my $cb = $self->{on_end_capture}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 321 | $cb->($doc, $self->{events}); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 321 | return; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 20 | *_nodes_from_events = \&DJabberd::SAXHandler::_nodes_from_events; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 20 | 1; | |||||||||||||||||||||||||||