blib/lib/WebDyne/Filter.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 34 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 141 CC 5 SCAR 17.5
CC
5
Cov
0%
request
12.0
response
12.0
import
2.0
CRAP 5.8
1 #
2 # This file is part of WebDyne.
3 #
4 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 # Full license text is available at:
10 #
11 # <http://dev.perl.org/licenses/>
12 #
13 package WebDyne::Filter;
14  
15  
16 # Compiler Pragma
17 #
18 use strict qw(vars);
19 use vars qw($VERSION @ISA);
20 use warnings;
21 no warnings qw(uninitialized);
22  
23  
24 # WebDyne Modules.
25 #
26 use WebDyne::Filter::Constant;
27 use WebDyne::Util;
28 use Data::Dumper;
29  
30  
31 # Version information
32 #
33 $VERSION='3.029';
34  
35  
36 # Shortcut error handler.
37 #
38 require WebDyne::Err;
39 *err_html=\&WebDyne::Err::err_html || *err_html;
40  
41  
42 # Debug
43 #
44 0 && debug("%s loaded, version $VERSION", __PACKAGE__);
45  
46  
47 # And done
48 #
49 1;
50  
51  
52 #------------------------------------------------------------------------------
53  
54  
55 sub import {
56  
57  
58 # Will only work if called from within a __PERL__ block in WebDyne
59 #
60 my $class=shift();
61 my $self_cr=UNIVERSAL::can(scalar(caller), 'self') || return;
62 my $self=$self_cr->() || return;
63  
64 $self->set_handler('WebDyne::Chain');
65 my $meta_hr=$self->meta();
66 push @{$meta_hr->{'webdynechain'}}, $class;
67  
68  
69 }
70  
71  
72 sub handler : method {
73  
74  
75 # Get class, request object
76 #
77 my ($self, $r, @param)=@_;
78 0 && debug("$self, r: $r, param: %s", Dumper(\@param));
79
80
81 # Modify request object
82 #
83 $self->request($r, @param);
84
85  
86 # Pass to next handler after intercepting print() routine
87 #
88 my $print_cr=ref($r)->can('print');
89 local *{ref($r).'::print'}=sub { $print_cr->($_[0], &response($self, @_)) };
90 return $self->SUPER::handler($r, @param);
91  
92 }
93  
94  
95 sub request {
96  
97 my ($self, $r, @param)=@_;
98 0 && debug("$self, r: $r, param: %s", Dumper(\@param));
99 if (ref(my $cr=$r->dir_config('WebDyneFilterRequest')) eq 'CODE') {
100 0 && debug("calling dir_config request filter handler: $cr");
101 return $cr->($self, $r, @param);
102 }
103 elsif (ref($cr=$WEBDYNE_FILTER_REQUEST_CR) eq 'CODE') {
104 0 && debug("calling global request filter handler: $cr");
105 return $cr->($self, $r, @param);
106 }
107 else {
108 0 && debug("no request filter handler, cr: $cr");
109 }
110
111 }
112  
113  
114 sub response {
115  
116 my ($self, $r, $html_sr)=@_;
117 if (ref(my $cr=$r->dir_config('WebDyneFilterResponse')) eq 'CODE') {
118 0 && debug("calling dir_config respones filter handler: $cr");
119 return $cr->($self, $r, $html_sr);
120 }
121 elsif (ref($cr=$WEBDYNE_FILTER_RESPONSE_CR) eq 'CODE') {
122 0 && debug("calling response filter handler: $cr");
123 return $cr->($self, $r, $html_sr);
124 }
125 else {
126 0 && debug("no repsonse filter handler, cr: $cr");
127 return $html_sr;
128 }
129
130 }
131  
132 __END__