XUL/ChangeManager.pm

filter: Statementstmt 44.5% 211 / 474 Branchbran 32.3% 55 / 170 Conditioncond 19.0% 12 / 63 MC/DCmcdc 5.4% 2 / 37 Subroutinesub 56.5% 39 / 69 Podpod 9.4% 5 / 53 totaltotal 37.4% 324 / 866 CC 116 SCAR 38.3
CC
116
Cov
39%
handle_TreeSelect
240.0
_set_uri
182.0
handle_Select
110.0
CRAP 46.0
« Component/XUL.pm ↑ Summary XUL/Request.pm »
1 package
2 POE::XUL::ChangeManager;
3 # $Id: ChangeManager.pm 1566 2010-11-03 03:13:32Z fil $
4 # Copyright Philip Gwyn 2007-2010. All rights reserved.
5 # Based on code Copyright 2003-2004 Ran Eilam. All rights reserved.
6  
7 #
8 # POE::XUL::Node and POE::XUL::TextNode will be calling us whenever they
9 # change attributes or children.
10 # We keep a list of POE::XUL::State objects that hold all these changes
11 # so that they may be mirrored in the browser. To speed things up a lot
12 # we break POE::XUL::State's encapsulation.
13 #
14 # We also maintain a list of all the nodes, available via ->getElementById.
15 #
16  
17 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 19 ▶use Carp qw( carp confess croak cluck );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 19 ▶use HTTP::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 19 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 19 ▶use POE::XUL::Logging;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 19 ▶use POE::XUL::State;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 19 ▶use POE::XUL::Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 19 ▶use Scalar::Util qw( weaken blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 19 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 19 our $VERSION = '0.0600';
31 19 our $WIN_NAME = 'POEXUL000';
32  
33 ##############################################################
34 sub new
35 {
36 6 ▶ my( $package ) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
37  
38 6 my $self = bless {
39 window => undef(),
40 current_event => undef(),
41 states => {},
42 nodes => {},
43 destroyed => [],
44 prepend => [],
45 other_windows => []
46 }, $package;
47  
48 6 $self->build_json;
49 6 return $self;
50 }
51  
52 ##############################################################
53 sub current_event
54 {
55 0 ▶ my $self = shift;
Subroutine current_event: not called CC=2 SCAR=17.9
Pod undocumented
56 0 my $rv = $self->{current_event};
57 0 ▶ $self->{current_event} = $_[0] if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
58 0 return $rv;
59 }
60  
61 ##############################################################
62 sub window
63 {
64 0 ▶ my( $self ) = @_;
Subroutine window: not called CC=1 SCAR=6.9
Pod undocumented
65 0 return $self->{window};
66 }
67  
68 ##############################################################
69 sub responded
70 {
71 0 ▶ my( $self ) = @_;
Subroutine responded: not called CC=1 SCAR=6.9
Pod undocumented
72 0 return $self->{responded};
73 }
74  
75  
76  
77 ##############################################################
78 sub build_json
79 {
80 6 ▶ my( $self ) = @_;
Subroutine build_json: called CC=1 SCAR=0.0
Pod undocumented
81 6 my $coder = JSON::XS->new->space_after( 1 );
82 6 $coder->ascii;
83 6 $self->{json_coder} = $coder;
84 }
85  
86 ##############################################################
87 sub json_encode
88 {
89 0 ▶ my( $self, $out ) = @_;
Subroutine json_encode: not called CC=2 SCAR=11.6
Pod undocumented
90 0 my $json = eval { $self->{json_coder}->encode( $out ) };
91 0 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
92 19 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 0 warn "Error encoding JSON: $@\n", Dumper $out;
94 0 my $err = $@;
95 0 $err =~ s/"/\x22/g;
96 0 $json = qq(["ERROR", "", "$err"]);
97 }
98  
99 DEBUG and
100 0 do {
101 my $foo = $json;
102 $foo =~ s/], /],\n/g;
103 19 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 xdebug "JSON: $foo\n";
105 xdebug "JSON size: ", length( $json ), "\n";
106 };
107  
108 # $json =~ s/], /],\n/g;
109 0 return $json;
110 }
111  
112 sub poexul_encode
113 {
114 0 ▶ my( $self, $out ) = @_;
Subroutine poexul_encode: not called CC=1 SCAR=6.9
Pod undocumented
115 0 DEBUG and xdebug "length=", 0+@$out;
116 0 return POE::XUL::Encode->encode( $out );
117 }
118  
119 ##############################################################
120 sub dispose
121 {
122 0 ▶ my( $self ) = @_;
Subroutine dispose: not called CC=5 SCAR=34.0
Pod undocumented
123  
124 0 foreach my $N ( @{ $self->{destroyed} },
125 0 values %{ $self->{nodes} },
126 0 values %{ $self->{states} } ) {
127 0 ▶ next unless defined $N and blessed $N and $N->can( 'dispose' );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $N and builtin::blessed($N) and $N->can("dispose") 0 0 0
Condition0%0/6
defined $N and builtin::blessed($N) and $N->can("dispose")
!ll&&!rl&&r
000
defined $N and builtin::blessed($N)
!ll&&!rl&&r
000
MC/DC0%0/3
defined $N and builtin::blessed($N) and $N->can("dispose")
defined $N builtin::blessed($N) $N->can("dispose")
Truth table0%0/4
A and B and C
A= defined $NB= builtin::blessed($N)C= $N->can("dispose")
ABCresult
0XX0
10X0
1100
1111
128 0 $N->dispose;
129 }
130 0 $self->{nodes} = {};
131 0 $self->{destroyed} = [];
132 0 $self->{states} = {};
133 0 $self->{prepend} = [];
134 0 $self->{other_windowx} = [];
135 }
136  
137 ##############################################################
138 # Get all changes, send to the browser
139 sub flush
140 {
141 53 ▶ my( $self ) = @_;
Subroutine flush: called CC=4 SCAR=14.0
Pod documented
142 53 local $_;
143 # TODO: we could cut down on trafic if we don't flush deleted nodes
144 # that are children of a deleted parent
145  
146 # XXX: How to prevent the flushing of deleted Window() and children?
147 53 my @out = @{ $self->{prepend} }; # our stuff
148 my @more = (
149 9 map( { $_->flush } @{$self->{destroyed}} ), # old stuff
150 $self->flush_node( $self->{window} ) # new/changed stuff
151 53 );
152 53 ▶ if( @more ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@more) 42 11 53
153 42 push @out, [ 'for', '' ], @more;
154 }
155  
156 53 ▶ foreach my $win ( @{ $self->{other_windows} || [] } ) {
Branch: 1 branch
BranchTrueFalseTotal
$self->{"other_windows"} or [] 0 53 53
157 0 push @out, [ 'for', $win->id ];
158 0 push @out, $self->flush_node( $win );
159 }
160 53 $self->{destroyed} = [];
161 53 $self->{prepend} = [];
162 53 return \@out;
163 }
164  
165 ##############################################################
166 sub flush_node
167 {
168 199 ▶ my ($self, $node) = @_;
Subroutine flush_node: called CC=7 SCAR=21.5
Pod undocumented
169 199 ▶ return unless $node and blessed $node;
Branch: 1 branch
BranchTrueFalseTotal
unless $node and builtin::blessed($node) 0 199 199
Condition33%1/3
$node and builtin::blessed($node)
!ll&&!rl&&r
00199
MC/DC0%0/2
$node and builtin::blessed($node)
$node builtin::blessed($node)
Truth table33%1/3
A and B
A= $nodeB= builtin::blessed($node)
ABresult
0X0
100
111
170 199 my $state = $self->node_state( $node );
171 199 ▶ return unless $state and blessed $state;
Branch: 1 branch
BranchTrueFalseTotal
unless $state and builtin::blessed($state) 0 199 199
Condition33%1/3
$state and builtin::blessed($state)
!ll&&!rl&&r
00199
MC/DC0%0/2
$state and builtin::blessed($state)
$state builtin::blessed($state)
Truth table33%1/3
A and B
A= $stateB= builtin::blessed($state)
ABresult
0X0
100
111
172  
173 199 my @defer = $state->as_deferred_command;
174 199 my @out = $state->flush;
175 199 ▶ unless( $state->{is_framify} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->{"is_framify"}) 199 0 199
176 199 push @out, $self->flush_node( $_ ) foreach $node->children;
177 }
178 199 push @out, @defer;
179 199 return @out;
180 }
181  
182 ##############################################################
183 sub node_state
184 {
185 539 ▶ my( $self, $node ) = @_;
Subroutine node_state: called CC=2 SCAR=6.9
Pod undocumented
186  
187 539 ▶ return $self->{states}{"$node"} if $self->{states}{"$node"};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"states"}{"$node"} 484 55 539
188  
189 55 my $is_tn = UNIVERSAL::isa($node, 'POE::XUL::TextNode');
190  
191 55 if( DEBUG ) {
192 confess "Not a node: [$node]" unless
193 UNIVERSAL::isa($node, 'POE::XUL::Node') or $is_tn;
194 }
195  
196 55 my $state = POE::XUL::State->new( $node );
197 55 $self->{states}{ "$node" } = $state;
198  
199 55 DEBUG and
200 xdebug "$self Created state ", $state->id, " for $node\n";
201  
202 55 $state->{is_textnode} = !! $is_tn;
203  
204 55 $self->register_node( $state->id, $node );
205  
206 55 return $state;
207 }
208  
209 ##############################################################
210 sub register_window
211 {
212 6 ▶ my( $self, $node ) = @_;
Subroutine register_window: called CC=3 SCAR=13.6
Pod undocumented
213 6 ▶ if( $self->{window} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'window'}) { } 0 6 6
214 0 DEBUG and xwarn "register_window $node";
215 0 push @{ $self->{other_windows} }, $node;
216 }
217 else {
218 6 $self->{window} = $node;
219 }
220 6 my $server = $POE::XUL::Application::server;
221 6 ▶ if( $server ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($server) 0 6 6
222 0 $server->register_window( $node );
223 }
224 }
225  
226 ##############################################################
227 sub unregister_window
228 {
229 0 ▶ my( $self, $node ) = @_;
Subroutine unregister_window: not called CC=5 SCAR=34.0
Pod undocumented
230 0 ▶ if( $node == $self->{window} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node == $self->{"window"}) 0 0 0
231 0 confess "You aren't allowed to unregister the main window!\n";
232 }
233 0 DEBUG and xwarn "unregister_window $node";
234 0 my @new;
235 0 ▶ foreach my $win ( @{ $self->{other_windows}||[] } ) {
Branch: 1 branch
BranchTrueFalseTotal
$self->{"other_windows"} or [] 0 0 0
236 0 ▶ next if $win == $node;
Branch: 1 branch
BranchTrueFalseTotal
if $win == $node 0 0 0
237 0 push @new, $win;
238 }
239  
240 0 $self->{other_windows} = \@new;
241 0 return;
242 }
243  
244 ##############################################################
245 sub register_node
246 {
247 56 ▶ my( $self, $id, $node ) = @_;
Subroutine register_node: called CC=5 SCAR=18.1
Pod undocumented
248
249 56 ▶ confess "Why you trying to be funny with me?" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 56 56
250 56 ▶ if( $self->{nodes}{$id} and not $self->{nodes}{$id}{disposed} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"nodes"}{$id} and not $self->{"nodes"}{$id}{"disposed"}) 0 56 56
Condition33%1/3
$self->{"nodes"}{$id} and not $self->{"nodes"}{$id}{"disposed"}
!ll&&!rl&&r
5600
MC/DC0%0/2
$self->{"nodes"}{$id} and not $self->{"nodes"}{$id}{"disposed"}
$self->{"nodes"}{$id} not $self->{"nodes"}{$id}{"disposed"}
Truth table33%1/3
A and not(B)
A= $self->{"nodes"}{$id}B= not $self->{"nodes"}{$id}{"disposed"}
ABresult
0X0
100
111
251 0 confess "I already have a node id=$id";
252 }
253 56 ▶ confess "Why you trying to be funny with me?" unless $node;
Branch: 1 branch
BranchTrueFalseTotal
unless $node 0 56 56
254 # xwarn "register $id is $node" if $id eq 'LIST_PREQ-PR_LAST_';
255 56 $self->{nodes}{ $id } = $node;
256 56 weaken( $self->{nodes}{ $id } );
257 56 return;
258 }
259  
260 ##############################################################
261 sub unregister_node
262 {
263 31 ▶ my( $self, $id, $node ) = @_;
Subroutine unregister_node: called CC=3 SCAR=11.0
Pod undocumented
264 # 2009/04 Perl's DESTROY behaviour can be random; if user created
265 # a new node w/ the same ID, we could see the second register before
266 # the DESTROY. So we make sure we are unregistering the right node.
267 31 ▶ if( ($self->{nodes}{$id}||'') ne $node ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($self->{"nodes"}{$id} || "") ne $node) 13 18 31
Condition100%2/2
$self->{'nodes'}{$id} || ''
l!l
1912
MC/DC100%1/1
$self->{'nodes'}{$id} || ''
$self->{'nodes'}{$id}
Truth table100%2/2
A
A= $self->{'nodes'}{$id}
Aresult
11
00
268 13 DEBUG and xwarn "Out of order unregister of $id";
269 13 return;
270 }
271 18 delete $self->{nodes}{ $id };
272 # 2007/12 do NOT $node->dispose here. unregister_node is also
273 # used by ->after_set_attribute()
274  
275 # xwarn "unregister $id is $node" if $id eq 'LIST_PREQ-PR_LAST_';
276 18 return;
277 }
278  
279 ##############################################################
280 sub getElementById
281 {
282 1 ▶ my( $self, $id ) = @_;
Subroutine getElementById: called CC=1 SCAR=0.0
Pod undocumented
283 1 return $self->{nodes}{ $id };
284 }
285  
286 ##############################################################
287 # We need for the node to have the same ID as the state
288 sub before_creation
289 {
290 38 ▶ my( $self, $node ) = @_;
Subroutine before_creation: called CC=2 SCAR=8.4
Pod undocumented
291 38 my $state = $self->node_state( $node );
292  
293 38 ▶ return if $node->getAttribute( 'id' );
Branch: 1 branch
BranchTrueFalseTotal
if $node->getAttribute("id") 38 0 38
294 0 warn "$node has no ID";
295 0 $node->setAttribute( id => $state->{id} );
296 }
297  
298  
299  
300 ##############################################################
301 sub after_destroy
302 {
303 28 ▶ my( $self, $node ) = @_;
Subroutine after_destroy: called CC=5 SCAR=16.1
Pod undocumented
304 # Don't use state_node, as it will create the state
305 28 my $state = delete $self->{states}{"$node"};
306 28 my $id;
307 28 ▶ if( $state ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($state) { } 8 20 28
elsif ($node->can('id')) { } 13 7 20
308 8 $id = $state->{id};
309 delete $self->{states}{ $state->{style} }
310 8 ▶ if $state->{style};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"style"} 0 8 8
311 }
312 elsif( $node->can( 'id' ) ) {
313 13 $id = $node->id;
314 }
315 28 ▶ return unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 7 21 28
316 21 $self->unregister_node( $id, $node );
317 }
318  
319 ##############################################################
320 sub after_set_attribute
321 {
322 82 ▶ my( $self, $node, $key, $value ) = @_;
Subroutine after_set_attribute: called CC=8 SCAR=22.4
Pod undocumented
323 82 ▶ return if $self->{ignorechanges};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ignorechanges"} 0 82 82
324 82 my $state = $self->node_state($node);
325  
326 82 ▶ if ($key eq 'tag') {
Branch: 3 branches
BranchTrueFalseTotal
if ($key eq 'tag') { } 37 45 82
elsif ($key eq 'id') { } 1 44 45
elsif ($key eq 'src' or $key eq 'href' or $key eq 'datasources') { } 0 44 44
327 37 $state->{tag} = $value;
328 37 ▶ $self->register_window( $node ) if $node->is_window;
Branch: 1 branch
BranchTrueFalseTotal
if $node->is_window 6 31 37
329 }
330 elsif( $key eq 'id' ) {
331 1 $self->_set_id( $node, $key, $value, $state );
332  
333 }
334 ▶ elsif( $key eq 'src' or $key eq 'href' or $key eq 'datasources' ) {
Condition33%2/6
$key eq "src" or $key eq "href" or $key eq "datasources"
l!l&&r!l&&!r
0044
$key eq "src" or $key eq "href"
l!l&&r!l&&!r
0044
MC/DC0%0/3
$key eq "src" or $key eq "href" or $key eq "datasources"
$key eq "src" $key eq "href" $key eq "datasources"
Truth table25%1/4
A or B or C
A= $key eq "src"B= $key eq "href"C= $key eq "datasources"
ABCresult
1XX1
01X1
0011
0000
335 0 $self->_set_uri( $node, $key, $value, $state );
336 }
337 else {
338 44 $state->set_attribute($key, $value);
339 # TODO: track exclusive things like focus()
340 }
341  
342 }
343  
344 sub _set_id
345 {
346 1 ▶ my( $self, $node, $key, $value, $state ) = @_;
Subroutine _set_id: called CC=2 SCAR=7.0
347  
348 1 ▶ return if $state->{id} eq $value;
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"id"} eq $value 0 1 1
349 1 DEBUG and
350 xdebug "node $state->{id} is now $value";
351 1 my $old_id = $state->{id};
352  
353 1 $state->set_attribute($key, $value);
354  
355 1 $self->unregister_node( $state->{id}, $node );
356 1 $state->{id} = $value;
357 1 $self->register_node( $state->{id}, $node );
358 }
359  
360 sub _set_uri
361 {
362 0 ▶ my( $self, $node, $key, $value, $state ) = @_;
Subroutine _set_uri: not called CC=13 SCAR=52.0
363  
364 0 my $hidden = "hidden-$key";
365 0 my $cb;
366 0 ▶ if( blessed $value ) {
Branch: 3 branches
BranchTrueFalseTotal
if (builtin::blessed($value)) { } 0 0 0
elsif (ref $value) { } 0 0 0
elsif (not $value =~ m[^(((ftp|file|data|https?):)|/)]) { } 0 0 0
367 0 ▶ unless( $value->can( 'mime_type' ) and
Branch: 1 branch
BranchTrueFalseTotal
unless ($value->can("mime_type") and $value->can("as_string") || $value->can("as_xml")) 0 0 0
Condition0%0/6
$value->can("mime_type") and $value->can("as_string") || $value->can("as_xml")
!ll&&!rl&&r
000
$value->can("as_string") or $value->can("as_xml")
l!l&&r!l&&!r
000
MC/DC0%0/3
$value->can("mime_type") and $value->can("as_string") || $value->can("as_xml")
$value->can("mime_type") $value->can("as_string") $value->can("as_xml")
Truth table0%0/4
A and B or C
A= $value->can("mime_type")B= $value->can("as_string")C= $value->can("as_xml")
ABCresult
0XX0
1000
11X1
1011
368 ( $value->can( 'as_string' ) or $value->can( 'as_xml' ) ) ) {
369 0 croak "$key object must implement as_string or as_xml, as well as mime_type methods";
370 }
371 0 DEBUG and xwarn "Callback to object $value";
372 0 $cb = $hidden;
373 }
374 elsif( ref $value ) {
375 # coderef or array ref for a callback
376 0 $cb = $hidden;
377 0 ▶ if( 'ARRAY' eq ref $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("ARRAY" eq ref $value) 0 0 0
378 0 ▶ if( 2 == @$value and 'HASH' eq ref $value->[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (2 == @$value and "HASH" eq ref $value->[-1]) 0 0 0
Condition0%0/3
2 == @$value and "HASH" eq ref $value->[-1]
!ll&&!rl&&r
000
MC/DC0%0/2
2 == @$value and "HASH" eq ref $value->[-1]
2 == @$value "HASH" eq ref $value->[-1]
Truth table0%0/3
A and B
A= 2 == @$valueB= "HASH" eq ref $value->[-1]
ABresult
0X0
100
111
379 0 $cb = { attribute => $cb,
380 extra => pop @$value
381 };
382 }
383 0 ▶ if( 1 == @$value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 == @$value) 0 0 0
384 0 unshift @$value,
385 $POE::Kernel::poe_kernel->get_active_session->ID;
386 }
387 }
388 }
389 # binary data
390 elsif( $value !~ m,^(((ftp|file|data|https?):)|/), ) { # not a URI
391 0 ▶ if( 30_000 < length $value or not $node->getAttribute( 'content-type' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (30000 < length $value or not $node->getAttribute('content-type')) { } 0 0 0
Condition0%0/3
30000 < length $value or not $node->getAttribute("content-type")
l!l&&r!l&&!r
000
MC/DC0%0/2
30000 < length $value or not $node->getAttribute("content-type")
30000 < length $value not $node->getAttribute("content-type")
Truth table0%0/3
A or not(B)
A= 30000 < length $valueB= not $node->getAttribute("content-type")
ABresult
1X1
011
000
392 # Don't use a data: url if
393 # - the data is too long
394 # - we don't have a content-type attribute
395 # In the latter case, we hope we'll have one, once we get to the
396 # callback
397 0 $cb = $hidden;
398 }
399 else {
400 0 my $ct = $node->getAttribute( 'content-type' );
401 0 my $uri = URI->new( "data:" );
402 0 $uri->media_type( $ct );
403 0 $uri->data( $value );
404 0 $state->set_attribute( $key, $uri->as_string );
405 0 return;
406 }
407 }
408 else {
409 0 $state->set_attribute($key, $value);
410 0 return;
411 }
412  
413  
414 # Setting a callback attribute cases Runner to set the value of
415 # the attribute to an URL that does a Callback event
416 # (see commandCallback).
417 # This then calls handle_Callback (see below) or the coderef/event
418 # defined in $value
419 # $cb must be either a value (which gets in attribute when it comes back)
420 # or a hashref { extra=>{}, attribute=>'' }
421 0 $state->set_attribute( callback => $cb );
422 0 local $self->{ignorechanges} = 1; # don't send to browser
423 0 $node->setAttribute( $hidden, $value );
424  
425 }
426  
427  
428 ##############################################################
429 sub after_remove_attribute
430 {
431 4 ▶ my( $self, $node, $key ) = @_;
Subroutine after_remove_attribute: called CC=4 SCAR=15.2
Pod undocumented
432 4 ▶ return if $self->{ignorechanges};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ignorechanges"} 0 4 4
433 4 my $state = $self->node_state( $node );
434  
435 delete $self->{states}{ $state->{style} } if $key eq 'style' and
436 4 ▶ $state->{style};
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "style" and $state->{"style"} 0 4 4
Condition33%1/3
$key eq "style" and $state->{"style"}
!ll&&!rl&&r
400
MC/DC0%0/2
$key eq "style" and $state->{"style"}
$key eq "style" $state->{"style"}
Truth table33%1/3
A and B
A= $key eq "style"B= $state->{"style"}
ABresult
0X0
100
111
437 4 $state->remove_attribute( $key );
438 }
439  
440 ##############################################################
441 sub after_method_call
442 {
443 1 ▶ my( $self, $node, $key, $args ) = @_;
Subroutine after_method_call: called CC=2 SCAR=7.0
Pod undocumented
444 1 ▶ return if $self->{ignorechanges};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ignorechanges"} 0 1 1
445 1 my $state = $self->node_state($node);
446  
447 1 $state->method_call($key, $args);
448 }
449  
450  
451  
452 ##############################################################
453 sub after_new_style
454 {
455 3 ▶ my( $self, $node ) = @_;
Subroutine after_new_style: called CC=2 SCAR=6.9
Pod undocumented
456 3 my $state = $self->node_state($node);
457 delete $self->{states}{ $state->{style} }
458 3 ▶ if $state->{style};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"style"} 2 1 3
459 3 my $style = $node->get_style;
460 3 $state->{style} = 0+$style;
461 3 $self->{states}{ $state->{style} } = $state;
462 3 $state->set_attribute( style => "$style" );
463 3 return;
464 }
465  
466 ##############################################################
467 sub after_style_change
468 {
469 8 ▶ my( $self, $style, $property, $value ) = @_;
Subroutine after_style_change: called CC=1 SCAR=0.0
Pod undocumented
470 8 my $state = $self->{states}{ 0+$style };
471 8 $state->style_change( $property, $value );
472 }
473  
474 ##############################################################
475 # when node added, set parent node state id on child node state
476 sub after__add_child_at_index
477 {
478 75 ▶ my( $self, $parent, $child, $index ) = @_;
Subroutine after__add_child_at_index: called CC=5 SCAR=16.1
Pod undocumented
479  
480 75 my $child_state = $self->node_state( $child );
481 75 $child_state->{parent} = $self->node_state( $parent );
482 75 weaken $child_state->{parent};
483 75 ▶ if( defined $child_state->{trueindex} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $child_state->{'trueindex'}) { } 0 75 75
484 0 $child_state->{trueindex} = $index;
485 }
486 else {
487 75 $child_state->{index} = $index;
488 }
489  
490 75 ▶ return unless @{$child->{children} || []};
Branch: 2 branches
BranchTrueFalseTotal
unless @{$child->{"children"} or [];} 51 24 75
$child->{"children"} or [] 36 39 75
491  
492 24 my $n = 0;
493 24 foreach my $subchild ( @{ $child->{children} } ) {
494 28 $self->after__add_child_at_index( $child, $subchild, $n );
495 28 $n++;
496 }
497 }
498  
499 sub set_trueindex
500 {
501 47 ▶ my( $self, $parent, $child, $trueindex ) = @_;
Subroutine set_trueindex: called CC=1 SCAR=0.0
Pod undocumented
502 47 my $child_state = $self->node_state( $child );
503 # Ignore trueindex for now... It breaks to many things
504 47 $child_state->{index} = $trueindex;
505 }
506  
507 ##############################################################
508 # when node destroyed, update state using set_destoyed
509 sub before_remove_child
510 {
511 9 ▶ my( $self, $parent, $child, $index ) = @_;
Subroutine before_remove_child: called CC=3 SCAR=11.1
Pod undocumented
512 # my $child = $parent->_compute_child_and_index($context->params->[1]);
513 # return unless $child;
514 9 ▶ Carp::croak "Why no index" unless defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 9 9
515 9 my $child_state = $self->node_state($child);
516 9 $child_state->is_destroyed( $parent, $index );
517 9 push @{$self->{destroyed}}, $child_state;
518  
519 9 delete $self->{states}{ "$child" };
520 delete $self->{states}{ $child_state->{style} }
521 9 ▶ if $child_state->{style};
Branch: 1 branch
BranchTrueFalseTotal
if $child_state->{"style"} 0 9 9
522 9 $self->unregister_node( $child_state->{id}, $child );
523 }
524  
525 ##############################################################
526 sub after_cdata_change
527 {
528 6 ▶ my( $self, $node ) = @_;
Subroutine after_cdata_change: called CC=1 SCAR=0.0
Pod undocumented
529 6 my $state = $self->node_state( $node );
530 6 $state->{cdata} = $node->{data};
531 6 $state->{is_new} = 1;
532 }
533  
534  
535  
536 ##############################################################
537 # So that we can detect changes between requests
538 sub request_start
539 {
540 0 ▶ my( $self, $event ) = @_;
Subroutine request_start: not called CC=1 SCAR=6.9
Pod undocumented
541 0 $self->{current_event} = $event;
542 0 $self->{responded} = 0;
543 }
544  
545 sub request_done
546 {
547 0 ▶ my( $self ) = @_;
Subroutine request_done: not called CC=2 SCAR=17.9
Pod undocumented
548 0 $self->{responded} = 1;
549 0 my $event = delete $self->{current_event};
550 0 ▶ $event->dispose if $event;
Branch: 1 branch
BranchTrueFalseTotal
if $event 0 0 0
551 0 undef( $event );
552  
553 # use Devel::Cycle;
554 # find_cycle( $self );
555 }
556  
557 ##############################################################
558 sub wrapped_error
559 {
560 0 ▶ my( $self, $string ) = @_;
Subroutine wrapped_error: not called CC=2 SCAR=17.9
Pod undocumented
561 0 ▶ if( $self->{current_event} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'current_event'}) { } 0 0 0
562 # xwarn "wrapped with $self->{current_event}";
563 0 $self->error_response( $self->{current_event}->response, $string );
564 }
565 else {
566 # TODO: what to do with errors that happen between events?
567 0 xlog "Error between events: $string";
568 }
569 }
570  
571 ##############################################################
572 sub error_response
573 {
574 0 ▶ my( $self, $resp, $string ) = @_;
Subroutine error_response: not called CC=1 SCAR=6.9
Pod undocumented
575 0 xlog "error_response $string";
576 # confess "ERROR $string";
577 0 return $self->cooked_response( $resp, [[ 'ERROR', '', $string]] );
578 }
579  
580 ##############################################################
581 sub response
582 {
583 0 ▶ my( $self, $resp ) = @_;
Subroutine response: not called CC=1 SCAR=6.9
Pod undocumented
584 0 my $out = $self->flush;
585 # xwarn "response = ", 0+@$out;
586 0 $self->cooked_response( $resp, $out );
587 }
588  
589 ##############################################################
590 sub cooked_response
591 {
592 0 ▶ my( $self, $resp, $out ) = @_;
Subroutine cooked_response: not called CC=4 SCAR=30.0
Pod undocumented
593  
594 0 ▶ if( $self->{responded} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"responded"}) 0 0 0
595 0 confess "Already responded";
596 0 xcarp "Already responded";
597 0 return;
598 }
599 0 ▶ confess "I need a response" unless $resp;
Branch: 1 branch
BranchTrueFalseTotal
unless $resp 0 0 0
600  
601 0 my $data;
602 0 ▶ unless( ref $out ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $out) { } 0 0 0
603 0 $data = $out;
604 }
605 elsif( 0 ) { # XXX config
606 $resp->content_type( POE::XUL::Encode->content_type );
607 $data = $self->poexul_encode( $out );
608 }
609 else {
610 0 $resp->content_type( 'application/json' ); #; charset=UTF-8' );
611 0 $data = $self->json_encode( $out );
612 }
613 0 DEBUG and
614 xdebug "Response=$data";
615 0 $self->__response( $resp, $data );
616 }
617  
618  
619 ##############################################################
620 sub xul_response
621 {
622 0 ▶ my( $self, $resp, $xul ) = @_;
Subroutine xul_response: not called CC=1 SCAR=6.9
Pod undocumented
623  
624 0 $resp->content_type( 'application/vnd.mozilla.xul+xml' );
625 0 $self->__response( $resp, $xul );
626 }
627  
628 ##############################################################
629 sub data_response
630 {
631 0 ▶ my( $self, $resp, $data ) = @_;
Subroutine data_response: not called CC=1 SCAR=6.9
Pod undocumented
632 # TODO: should we check if there is anything to be flushed?
633 # Idealy, we'd do it non-destructively, so that we could warn but
634 # the changes would wait for next request
635 0 $self->__response( $resp, $data );
636 }
637  
638 ##############################################################
639 ## This should be moved to Controler
640 sub __response
641 {
642 0 ▶ my( $self, $resp, $content ) = @_;
Subroutine __response: not called CC=1 SCAR=2.9
643  
644
645 0 do {
646 # HTTP exptects content-length to be number of octets, not chars
647 # The UTF-8 that JSON::XS is producing was screwing up length()
648 19 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
649 0 $resp->content_length( length $content );
650 };
651 0 $resp->content( $content );
652 0 $resp->code( RC_OK );
653 0 $resp->continue(); # but only if we've stoped!
654  
655 0 $self->request_done;
656 }
657  
658  
659  
660 ##############################################################
661 sub SID
662 {
663 0 ▶ my( $self, $SID ) = @_;
Subroutine SID: not called CC=1 SCAR=6.9
Pod undocumented
664 0 push @{ $self->{ prepend } }, $self->build_SID( $SID );
665 }
666  
667  
668 ##############################################################
669 sub build_SID
670 {
671 0 ▶ my( $self, $SID ) = @_;
Subroutine build_SID: not called CC=1 SCAR=6.9
Pod undocumented
672 0 return POE::XUL::State->make_command_SID( $SID );
673 }
674  
675 ##############################################################
676 # Send a boot message to the client
677 sub Boot
678 {
679 0 ▶ my( $self, $msg ) = @_;
Subroutine Boot: not called CC=1 SCAR=6.9
Pod undocumented
680 0 push @{ $self->{prepend} }, POE::XUL::State->make_command_boot( $msg );
681 }
682  
683  
684  
685  
686  
687  
688  
689  
690 ##############################################################
691 # Side-effects for a given event
692 ##############################################################
693 sub handle_Click
694 {
695 0 ▶ my( $self, $event ) = @_;
Subroutine handle_Click: not called CC=1 SCAR=6.9
Pod undocumented
696 0 return;
697 }
698  
699 ##############################################################
700 # A textbox was changed
701 # Uses source, value
702 sub handle_Change
703 {
704 0 ▶ my( $self, $event ) = @_;
Subroutine handle_Change: not called CC=1 SCAR=6.9
Pod undocumented
705 0 local $self->{ignorechanges} = 1;
706 0 DEBUG and
707 xdebug "Change value=", $event->value, " source=", $event->source;
708 0 $event->source->setAttribute( value=> $event->value );
709 }
710  
711 ##############################################################
712 sub handle_BoxClick
713 {
714 0 ▶ my( $self, $event ) = @_;
Subroutine handle_BoxClick: not called CC=1 SCAR=6.9
Pod undocumented
715 0 local $self->{ignorechanges} = 1;
716 0 my $checked = $event->checked;
717  
718 0 DEBUG and xdebug "Click event=$event source=", $event->source->id;
719 # $checked = defined $checked && $checked eq 'true'? 1: 0;
720 0 $event->checked( $checked );
721 0 $event->source->checked( $checked );
722 }
723  
724 ##############################################################
725 # A radio button was clicked
726 # Uses : source, selectedId
727 sub handle_RadioClick
728 {
729 0 ▶ my( $self, $event ) = @_;
Subroutine handle_RadioClick: not called CC=5 SCAR=34.0
Pod undocumented
730 0 local $self->{ignorechanges} = 1;
731 0 my $selectedId = $event->selectedId;
732  
733 0 DEBUG and
734 xdebug "RadioClick source=",
735 ($event->source->id||$event->source),
736 " selectedId=$selectedId";
737 0 my $radiogroup = $event->source;
738 0 my $radio = $self->getElementById( $selectedId );
739  
740 0 ▶ die "Can't find element $selectedId for RadioClick"
Branch: 1 branch
BranchTrueFalseTotal
unless $radio 0 0 0
741 unless $radio;
742  
743 0 $event->event( 'Click' );
744 0 foreach my $C ( $radiogroup->children ) {
745 0 ▶ if( $C == $radio ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($C == $radio) { } 0 0 0
elsif ($C->selected) { } 0 0 0
746 0 $C->setAttribute( 'selected', 1 );
747 0 DEBUG and xdebug "Found $selectedId\n";
748 # If there was a Click handler on the Radio, we
749 # revert to the former behaviour of running that handler
750 # xdebug "Going to C=$C id=", $C->id;
751 0 $event->bubble_to( $radiogroup );
752 0 $event->__source_id( $C->id );
753 }
754 elsif( $C->selected ) {
755 0 $C->removeAttribute( 'selected' );
756 }
757 }
758 }
759  
760 ##############################################################
761 # A list item was selected
762 # Uses: source, selectedIndex, value
763 sub handle_Select
764 {
765 0 ▶ my( $self, $event ) = @_;
Subroutine handle_Select: not called CC=10 SCAR=47.0
Pod undocumented
766 0 local $self->{ignorechanges} = 1;
767  
768 0 my $menulist = $event->source;
769  
770 0 ▶ if( $menulist->tagName eq 'tree' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($menulist->tagName eq "tree") 0 0 0
771 0 return $self->handle_TreeSelect( $event );
772 }
773  
774 0 my $I = $event->selectedIndex;
775 # selecting text in a textbox!
776 0 ▶ return unless defined $I and $I ne 'undefined';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $I and $I ne "undefined" 0 0 0
Condition0%0/3
defined $I and $I ne "undefined"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $I and $I ne "undefined"
defined $I $I ne "undefined"
Truth table0%0/3
A and B
A= defined $IB= $I ne "undefined"
ABresult
0X0
100
111
777 0 my $oI = $menulist->selectedIndex;
778  
779 0 DEBUG and
780 xdebug "Select was=$oI, now=$I";
781  
782 0 ▶ if( defined $I and $I == -1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $I and $I == -1) { } 0 0 0
elsif ($menulist->editable and $oI and $oI == -1) { } 0 0 0
Condition0%0/3
defined $I and $I == -1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $I and $I == -1
defined $I $I == -1
Truth table0%0/3
A and B
A= defined $IB= $I == -1
ABresult
0X0
100
111
783 0 xdebug "Change Combo I=$I value=", $event->value;
784 0 $menulist->selectedIndex( $I );
785 0 $menulist->value( $event->value );
786 0 return;
787 }
788 ▶ elsif( $menulist->editable and $oI and $oI == -1 ) {
Condition0%0/6
$menulist->editable and $oI and $oI == -1
!ll&&!rl&&r
000
$menulist->editable and $oI
!ll&&!rl&&r
000
MC/DC0%0/3
$menulist->editable and $oI and $oI == -1
$menulist->editable $oI $oI == -1
Truth table0%0/4
A and B and C
A= $menulist->editableB= $oIC= $oI == -1
ABCresult
0XX0
10X0
1100
1111
789 0 xdebug "Change Combo remove 'value'";
790 0 $menulist->removeAttribute( 'value' );
791 }
792  
793 0 $self->Select_choose( $event, $oI, 'selected', 0 );
794 0 $menulist->selectedIndex( $I );
795 0 my $item = $self->Select_choose( $event, $I, 'selected', 1 );
796  
797 0 ▶ if( $item ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item) 0 0 0
798 0 xdebug "Select $I.label=", $item->label;
799 # The event should go to the item first, then the "parent"
800 0 $event->bubble_to( $event->source );
801 0 $event->__source_id( $item->id );
802 # $menulist->value( $item->value );
803 }
804 }
805  
806  
807 ##############################################################
808 # Turn one menuitem on/off
809 sub Select_choose
810 {
811 0 ▶ my( $self, $event, $I, $att, $value ) = @_;
Subroutine Select_choose: not called CC=6 SCAR=37.4
Pod undocumented
812 0 my $list = $event->source;
813 0 ▶ return unless $list;
Branch: 1 branch
BranchTrueFalseTotal
unless $list 0 0 0
814 0 ▶ return unless $list->first_child;
Branch: 1 branch
BranchTrueFalseTotal
unless $list->first_child 0 0 0
815 0 ▶ return unless defined $I;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $I 0 0 0
816  
817 0 my $item = $list->getItemAtIndex( $I );
818 0 ▶ return unless $item;
Branch: 1 branch
BranchTrueFalseTotal
unless $item 0 0 0
819  
820 0 local $self->{ignorechanges} = 0;
821 0 ▶ if( $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 0 0 0
822 0 $item->setAttribute( $att, $value );
823 }
824 else {
825 0 $item->removeAttribute( $att );
826 }
827 0 return $item;
828 }
829  
830 ##############################################################
831 # User picked a colour
832 sub handle_Pick
833 {
834 0 ▶ my( $self, $event ) = @_;
Subroutine handle_Pick: not called CC=1 SCAR=6.9
Pod undocumented
835 0 local $self->{ignorechanges} = 1;
836 0 $event->source->color($self->color);
837 }
838  
839 ##############################################################
840 # Image src="" callbackup
841 sub handle_Callback
842 {
843 0 ▶ my( $self, $event ) = @_;
Subroutine handle_Callback: not called CC=5 SCAR=34.0
Pod undocumented
844 0 my $node = $event->source;
845 0 my $key = $event->attribute;
846 # xdebug( "Callback $key" );
847 0 my $cb = $node->getAttribute( $key );
848 0 ▶ if( blessed $cb ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($cb)) { } 0 0 0
elsif (ref $cb) { } 0 0 0
849 0 DEBUG and xwarn "Callback with $cb";
850 0 $event->response->content_type(
851 $cb->mime_type
852 );
853 0 ▶ if( $cb->can( 'as_xml' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb->can('as_xml')) { } 0 0 0
854 0 $event->data_response( $cb->as_xml );
855 }
856 else {
857 0 $event->data_response( $cb->as_string );
858 }
859 }
860 elsif( ref $cb ) {
861 0 ▶ if( 'CODE' eq ref $cb ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('CODE' eq ref $cb) { } 0 0 0
862 0 $cb->( $node, $event );
863 }
864 else {
865 # xdebug( join '/', @$cb );
866 0 $POE::Kernel::poe_kernel->call( @$cb, $node, $event );
867 }
868 }
869 else {
870 0 $event->response->content_type(
871 $node->getAttribute( 'content-type' )
872 );
873 0 $event->data_response( $cb );
874 }
875 }
876  
877 ##############################################################
878 # A row of a tree was selected
879 # Uses: source, selectedIndex, value
880 sub handle_TreeSelect
881 {
882 0 ▶ my( $self, $event ) = @_;
Subroutine handle_TreeSelect: not called CC=15 SCAR=54.8
Pod undocumented
883  
884 0 local $self->{ignorechanges} = 1;
885  
886 0 my $tree = $event->source;
887 0 my $rowN = $event->selectedIndex;
888  
889 # Handle user sorting of RDF trees
890 0 ▶ if( $event->primary_col ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->primary_col) 0 0 0
891 0 xdebug "primary_col=", $event->primary_col;
892 0 xdebug "primary_text=", $event->primary_text;
893 0 my $rdf = $tree->getAttribute( 'hidden-datasources' );
894 0 xdebug "rdf: $rdf";
895 0 ▶ if( blessed( $rdf ) and $rdf->can( 'index_of' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($rdf) and $rdf->can("index_of")) 0 0 0
Condition0%0/3
builtin::blessed($rdf) and $rdf->can("index_of")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($rdf) and $rdf->can("index_of")
builtin::blessed($rdf) $rdf->can("index_of")
Truth table0%0/3
A and B
A= builtin::blessed($rdf)B= $rdf->can("index_of")
ABresult
0X0
100
111
896 0 $rowN = $rdf->index_of( $event->primary_col, $event->primary_text );
897 0 xdebug "true index is $rowN";
898 0 $tree->selectedIndex( $rowN );
899 0 $event->selectedIndex( $rowN );
900 0 return;
901 }
902 }
903  
904 0 $tree->selectedIndex( $rowN );
905  
906 # Find the xul:treechildren node
907 0 my $treechildren;
908 0 foreach my $node ( $tree->children ) {
909 0 ▶ next unless $node->tagName eq 'treechildren';
Branch: 1 branch
BranchTrueFalseTotal
unless $node->tagName eq "treechildren" 0 0 0
910 0 $treechildren = $node;
911 0 last;
912 }
913  
914 0 ▶ unless( $treechildren ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($treechildren) 0 0 0
915 # This happens when a tree has a datasource, like RDF
916 0 DEBUG and xdebug "Select on a tree w/o treechildren";
917 0 return;
918 }
919  
920 DEBUG and
921 0 xdebug "treechildren=$treechildren";
922
923 # Find the row nodes. This could be xul:treeitem or xul::treerow
924 0 my @rows;
925 0 foreach my $treeitem ( $treechildren->children ) {
926 0 my $first = $treeitem->first_child;
927 0 ▶ if( $first and $first->tagName eq 'treerow' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first and $first->tagName eq 'treerow') { } 0 0 0
Condition0%0/3
$first and $first->tagName eq "treerow"
!ll&&!rl&&r
000
MC/DC0%0/2
$first and $first->tagName eq "treerow"
$first $first->tagName eq "treerow"
Truth table0%0/3
A and B
A= $firstB= $first->tagName eq "treerow"
ABresult
0X0
100
111
928 0 push @rows, $first;
929 }
930 else {
931 0 push @rows, $treeitem;
932 }
933 }
934 DEBUG and
935 0 xdebug "Found ", 0+@rows, " rows";
936  
937 0 ▶ for( my $r = 0 ; $r<=$#rows ; $r++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r <= $#rows) 0 0 0
938 0 my $prop = $rows[$r]->properties;
939 0 ▶ if( $r == $rowN ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($r == $rowN) { } 0 0 0
elsif ($prop =~ s/\s*selected\s*//g) { } 0 0 0
940 0 $prop =~ s/\s*selected\s*//g;
941 0 ▶ if( $prop ) { $prop .= ' selected' }
Branch: 1 branch
BranchTrueFalseTotal
if ($prop) { } 0 0 0
942 0 else { $prop = 'seelected' }
943 0 DEBUG and xdebug "Row $r properties=$prop";
944 0 $rows[$r]->properties( $prop );
945 0 $event->bubble_to( $tree );
946 0 $event->__source_id( $rows[$r]->id );
947 }
948 elsif( $prop =~ s/\s*selected\s*//g ) {
949 0 DEBUG and xdebug "Row $r properties=$prop";
950 0 ▶ $rows[$r]->properties( $prop||'' );
Condition0%0/2
$prop || ''
l!l
00
MC/DC0%0/1
$prop || ''
$prop
Truth table0%0/2
A
A= $prop
Aresult
11
00
951 }
952 }
953  
954 0 return;
955 }
956  
957  
958  
959  
960  
961  
962 ##############################################################
963 sub Prepend
964 {
965 6 ▶ my( $self, $cmd ) = @_;
Subroutine Prepend: called CC=1 SCAR=0.0
Pod undocumented
966 6 push @{ $self->{prepend} }, $cmd;
967 6 return 0+@{ $self->{prepend} };
968 }
969  
970 ##############################################################
971 sub flush_to_prepend
972 {
973 1 ▶ my( $self ) = @_;
Subroutine flush_to_prepend: called CC=2 SCAR=7.0
Pod undocumented
974 1 my $out = $self->flush;
975 1 ▶ return unless @$out;
Branch: 1 branch
BranchTrueFalseTotal
unless @$out 0 1 1
976 1 push @{ $self->{prepend} }, @$out;
977 1 return 0+@{ $self->{prepend} };
978 }
979  
980 ##############################################################
981 sub timeslice
982 {
983 2 ▶ my( $self ) = @_;
Subroutine timeslice: called CC=1 SCAR=0.0
Pod documented
984 2 $self->Prepend( [ 'timeslice' ] );
985 }
986  
987 ##############################################################
988 sub popup_window
989 {
990 4 ▶ my( $self, $name, $features ) = @_;
Subroutine popup_window: called CC=4 SCAR=14.0
Pod documented
991 4 ▶ $name ||= $WIN_NAME++;
Condition66%2/3
$name ||= $POE::XUL::ChangeManager::WIN_NAME++
l!l&&r!l&&!r
310
MC/DC0%0/2
$name ||= $POE::XUL::ChangeManager::WIN_NAME++
$name $POE::XUL::ChangeManager::WIN_NAME++
Truth table66%2/3
A ||= B
A= $nameB= $POE::XUL::ChangeManager::WIN_NAME++
ABresult
1X1
011
000
992 4 ▶ $features ||= {};
Condition100%2/2
$features ||= {}
l!l
22
MC/DC100%1/1
$features ||= {}
$features
Truth table100%2/2
A
A= $features
Aresult
11
00
993 4 ▶ croak "Features must be a hashref" unless 'HASH' eq ref $features;
Branch: 1 branch
BranchTrueFalseTotal
unless "HASH" eq ref $features 0 4 4
994 4 $self->Prepend( [ 'popup_window', $name, $features ] );
995 4 return $name;
996 }
997  
998 ##############################################################
999 sub close_window
1000 {
1001 0 ▶ my( $self, $name ) = @_;
Subroutine close_window: not called CC=1 SCAR=6.9
Pod documented
1002 0 $self->Prepend( [ 'close_window', $name ] );
1003 }
1004  
1005 ##############################################################
1006 # Send some instructions to Runner.js. Or other control of the CM
1007 sub instruction
1008 {
1009 9 ▶ my( $self, $inst ) = @_;
Subroutine instruction: called CC=7 SCAR=20.1
Pod documented
1010  
1011 9 my( $op, @param );
1012 9 ▶ if( ref $inst ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inst) { } 4 5 9
1013 4 ( $op, @param ) = @$inst;
1014 }
1015 else {
1016 5 $op = $inst;
1017 }
1018  
1019 9 ▶ if( $op eq 'flush' ) { # flush changes to output buffer
Branch: 5 branches
BranchTrueFalseTotal
if ($op eq 'flush') { } 1 8 9
elsif ($op eq 'empty') { } 2 6 8
elsif ($op eq 'timeslice') { } 2 4 6
elsif ($op eq 'popup_window') { } 4 0 4
elsif ($op eq 'close_window') { } 0 0 0
1020 1 return $self->flush_to_prepend;
1021 }
1022 elsif( $op eq 'empty' ) { # empty all changes
1023 2 return $self->flush;
1024 }
1025 elsif( $op eq 'timeslice' ) { # give up a timeslice
1026 2 return $self->timeslice;
1027 }
1028 elsif( $op eq 'popup_window' ) {
1029 4 return $self->popup_window( @param );
1030 }
1031 elsif( $op eq 'close_window' ) {
1032 0 return $self->close_window( @param );
1033 }
1034 else {
1035 0 die "Unknown instruction: $op";
1036 }
1037 }
1038  
1039 19 1;
1040  
1041 __END__
« Component/XUL.pm ↑ Summary XUL/Request.pm »