lib/XML/Schema/Scheduler.pm

filter: Statementstmt 97.0% 66 / 68 Branchbran 60.5% 23 / 38 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 85.7% 102 / 119 CC 23 SCAR 21.2
CC
23
Cov
84%
__ANON__
15.9
init
6.0
_schedule_method_factory
5.2
CRAP 8.3
« lib/XML/Schema/Scoped.pm ↑ Summary lib/XML/Schema/Particle.pm »
1 #============================================================= -*-perl-*-
2 #
3 # XML::Schema::Scheduler.pm
4 #
5 # DESCRIPTION
6 # Module implementing an object class for scheduling actions around
7 # an XML Schema.
8 #
9 # AUTHOR
10 # Andy Wardley <abw@kfs.org>
11 #
12 # COPYRIGHT
13 # Copyright (C) 2001 Canon Research Centre Europe Ltd.
14 # All Rights Reserved.
15 #
16 # This module is free software; you can redistribute it and/or
17 # modify it under the same terms as Perl itself.
18 #
19 # REVISION
20 # $Id: Scheduler.pm,v 1.1.1.1 2001/08/29 14:30:17 abw Exp $
21 #
22 #========================================================================
23  
24 package XML::Schema::Scheduler;
25  
26 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 28 ▶use base qw( XML::Schema::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 28 ▶use vars qw( $VERSION $DEBUG $ERROR @SCHEDULES );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 28 $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
31 28 ▶$DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $XML::Schema::Scheduler::DEBUG 28 0 28
32 28 $ERROR = '';
33  
34 # default schedule lists (can be overridden in a subclass)
35 28 @SCHEDULES = qw( before after );
36  
37  
38 #use constant TAIL => 0;
39 #use constant HEAD => 1;
40  
41 #------------------------------------------------------------------------
42 # init()
43 #------------------------------------------------------------------------
44  
45 28 *init_scheduler = \&init;
46  
47 329 ▶sub init {
Subroutine init: called CC=6 SCAR=17.9
Pod documented
48 329 my ($self, $config) = @_;
49 329 my ($s, $value, $schedule);
50 329 my $class = ref $self;
51  
52 329 my ($schedules) = @{ $self->_baseargs( { first => 1 },
53 qw( @SCHEDULES ) ) };
54  
55 329 local $" = ', ';
56 329 ▶ $self->DEBUG("Schedule lists for $class: [ @$schedules ]\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Scheduler::DEBUG 0 329 329
57 if $DEBUG;
58  
59 329 foreach $s (@$schedules) {
60 28 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
61 499 ($schedule) = @{ $self->_baseargs("\@SCHEDULE_$s") };
62  
63 push(@$schedule, UNIVERSAL::isa($value, 'ARRAY') ? @$value : $value)
64 499 ▶ if defined ($value = $config->{"schedule_$s"});
Branch: 2 branches
BranchTrueFalseTotal
if defined($value = $$config{"schedule_$s"}) 3 496 499
UNIVERSAL::isa($value, 'ARRAY') ? : 1 2 3
65  
66 499 $self->{"_SCHEDULE_$s"} = $schedule;
67 499 ▶ $self->DEBUG("_SCHEDULE_$s => [ @$schedule ]\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Scheduler::DEBUG 0 499 499
68 if $DEBUG;
69 }
70 329 $self->_schedule_method_factory(@$schedules);
71  
72 329 return $self;
73 }
74  
75 #------------------------------------------------------------------------
76 # _schedule_method_factory(@methods)
77 #
78 # Iterates $m through each of the method names passed as arguments and
79 # installs two closures as the methods "schedule_$m" and "activate_$m"
80 # in the subclass package. If the "schedule_$m" method is already
81 # defined then it skips this step (assumes that "activate_$m" is also
82 # defined but doesn't actually check). These methods can then be used
83 # to schedule actions and subsequently activate them for each of the
84 # schedule lists defined for a subclass object.
85 #------------------------------------------------------------------------
86  
87 329 ▶sub _schedule_method_factory {
Subroutine _schedule_method_factory: called CC=5 SCAR=16.6
88 329 my ($self, @methods) = @_;
89 329 my $class = ref $self;
90 329 foreach my $m (@methods) {
91 28 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
92 499 ▶ if (defined &{$class . "::schedule_$m"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &{$class . "::schedule_$m";}) { } 317 182 499
93 317 ▶ $self->DEBUG("schedule_$m method already defined in $class, skipping\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Scheduler::DEBUG 0 317 317
94 if $DEBUG;
95 }
96 else {
97 182 ▶ $self->DEBUG("creating schedule/action methods in $class\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Scheduler::DEBUG 0 182 182
98 if $DEBUG;
99 182 ▶ *{$class . "::schedule_$m"} = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
100 6 my ($self, $action, $at_head) = @_;
101 6 ▶ $at_head ||= 0;
Condition100%2/2
$at_head ||= 0
l!l
15
MC/DC100%1/1
$at_head ||= 0
$at_head
Truth table100%2/2
A
A= $at_head
Aresult
11
00
102 6 ▶ $self->DEBUG("schedule_$m($action, $at_head)\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Scheduler::DEBUG 0 6 6
103 if $DEBUG;
104 6 ▶ if ($at_head) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at_head) { } 1 5 6
105 1 unshift(@{ $self->{"_SCHEDULE_$m"} }, $action);
106 }
107 else {
108 5 push(@{ $self->{"_SCHEDULE_$m"} }, $action);
109 }
110 182 };
111 182 ▶ *{$class . "::activate_$m"} = sub {
Subroutine __ANON__: called CC=11 SCAR=27.7
112 415 my ($self, $infoset) = @_;
113 415 ▶ $infoset = { result => $infoset } unless UNIVERSAL::isa($infoset, 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($infoset, "HASH") 6 409 415
114 415 foreach my $action (@{ $self->{"_SCHEDULE_$m"} }) {
115 # TODO: check return value for ERROR/STOP/EXPLODE/etc
116 27 ▶ if (ref $action eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $action eq 'CODE') { } 26 1 27
elsif (ref $action eq 'ARRAY') { } 1 0 1
117 26 ▶ $self->DEBUG("calling $action($self, $infoset)\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Scheduler::DEBUG 0 26 26
118 if $DEBUG;
119 26 ▶ return unless defined &$action($self, $infoset);
Branch: 1 branch
BranchTrueFalseTotal
unless defined &$action($self, $infoset) 0 26 26
120 }
121 elsif (ref $action eq 'ARRAY') {
122 1 my ($object, $method, @args) = @$action;
123 1 ▶ $self->DEBUG("calling $object->$method($self, $infoset, @args)\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Scheduler::DEBUG 0 1 1
124 if $DEBUG;
125 1 ▶ return unless defined $object->$method($self, $infoset, @args);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $object->$method($self, $infoset, @args) 0 1 1
126 }
127 else {
128 0 ▶ $self->DEBUG("calling $self->$action($infoset)\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Scheduler::DEBUG 0 0 0
129 if $DEBUG;
130 0 ▶ return unless defined $self->$action($infoset);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->$action($infoset) 0 0 0
131 }
132 }
133 415 return $infoset;
134 182 };
135 }
136 }
137 }
138  
139  
140  
141
142  
143 28 1;
144  
145 __END__
« lib/XML/Schema/Scoped.pm ↑ Summary lib/XML/Schema/Particle.pm »