HeavyCGI/ExePlan.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 118 CC 12 SCAR 39.1
CC
12
Cov
0%
walk
90.0
new
20.0
BEGIN
2.0
CRAP 50.0
1 package Apache::HeavyCGI::ExePlan;
2 use Apache::HeavyCGI; # want only the instance_of method
3 use strict;
4 # use fields qw(PLAN DEBUG FUNCTIONAL WATCHVARIABLE);
5  
6 use vars '$VERSION';
7 $VERSION = sprintf "%d.%03d", q$Revision: 1.10 $ =~ /(\d+)\.(\d+)/;
8  
9 # no singleton, every Application can have its own execution plan even
10 # every object can have it's own, although, it probably doesn't pay
11  
12 sub new {
13 my($me,%arg) = @_;
14 my $methods = $arg{METHODS} || [qw(header parameter)];
15 my $classes = $arg{CLASSES} || [];
16 my $functional = $arg{WALKTYPE} eq "f";
17 my $watchvariable = $arg{WATCHVARIABLE};
18 my $debug = $arg{DEBUG} || 0; #### undocumented
19 my @plan;
20 for my $method (@$methods) {
21 for my $class (@$classes) {
22 my($obj,$subr);
23 eval { $obj = $class->instance; };
24 if ($@) {
25 $obj = Apache::HeavyCGI->instance_of($class);
26 }
27 next unless $subr = $obj->can($method);
28 if ($functional) {
29 push @plan, $subr, $obj;
30 } else {
31 push @plan, $obj, $method;
32 }
33 }
34 }
35 no strict "refs";
36 my $self = bless {}, $me;
37 $self->{PLAN} = [ @plan ];
38 $self->{DEBUG} = $debug;
39 $self->{FUNCTIONAL} = $functional;
40 $self->{WATCHVARIABLE} = $watchvariable;
41 $self;
42 }
43  
44 sub walk {
45 my Apache::HeavyCGI::ExePlan $self = shift;
46 my Apache::HeavyCGI $application = shift;
47 if ($self->{WATCHVARIABLE}) {
48 require Data::Dumper;
49 }
50 for (my $i=0;;$i+=2) {
51 warn sprintf(
52 "entering method[%s] walktype[%s]",
53 $self->{PLAN}[$i]."::".$self->{PLAN}[$i+1],
54 $self->{FUNCTIONAL} ? "f" : "m",
55 ) if $self->{DEBUG} && $self->{DEBUG} & 1;
56 my $before = $self->{WATCHVARIABLE} ?
57 Data::Dumper::Dumper($application->{$self->{WATCHVARIABLE}}) :
58 "";
59 if ($self->{FUNCTIONAL}) {
60 my $subr = $self->{PLAN}[$i] or last;
61 my $obj = $self->{PLAN}[$i+1];
62 $subr->($obj,$application);
63 } else {
64 my $obj = $self->{PLAN}[$i] or last;
65 my $method = $self->{PLAN}[$i+1];
66 $obj->$method($application);
67 }
68 warn sprintf "exiting" if $self->{DEBUG} && $self->{DEBUG} & 2;
69 my $after = $self->{WATCHVARIABLE} ?
70 Data::Dumper::Dumper($application->{$self->{WATCHVARIABLE}}) : "";
71 unless ($before eq $after) {
72 warn sprintf(
73 "variable %s changed value from[%s]to[%s] in method[%s]",
74 $self->{WATCHVARIABLE},
75 $before,
76 $after,
77 $self->{PLAN}[$i]."::".$self->{PLAN}[$i+1],
78 );
79 }
80 }
81 }
82  
83 1;
84  
85 __END__