| 1 | package CGI::Untaint::object; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | CGI::Untaint::object - base class for Input Handlers | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | package MyUntaint::foo; | ||||||||||
| 10 | |||||||||||
| 11 | use base 'CGI::Untaint::object'; | ||||||||||
| 12 | |||||||||||
| 13 | sub _untaint_re { | ||||||||||
| 14 | return qr/$your_regex/; | ||||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | sub is_valid { | ||||||||||
| 18 | my $self = shift; | ||||||||||
| 19 | return is_ok($self->value); | ||||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 1; | ||||||||||
| 23 | |||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||
| 25 | |||||||||||
| 26 | This is the base class that all Untaint objects should inherit | ||||||||||
| 27 | from. | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | 1 | ▶ | sub _new { | ||||||||
|
Subroutine
_new: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 1 | my ($class, $h, $raw) = @_; | |||||||||
| 35 | 1 | bless { | |||||||||
| 36 | _obj => $h, | ||||||||||
| 37 | _raw => $raw, | ||||||||||
| 38 | _clean => undef, | ||||||||||
| 39 | } => $class; | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | =head1 METHODS TO SUBCLASS | ||||||||||
| 43 | |||||||||||
| 44 | =head2 is_valid / _untaint_re | ||||||||||
| 45 | |||||||||||
| 46 | Your subclass should either provide a regular expression in _untaint_re | ||||||||||
| 47 | (and yes, I should really make this public), or an entire is_valid method. | ||||||||||
| 48 | |||||||||||
| 49 | =cut | ||||||||||
| 50 | |||||||||||
| 51 | 1 | ▶ | sub is_valid { 1 } | ||||||||
|
Subroutine
is_valid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 52 | |||||||||||
| 53 | =head1 METHODS TO CALL | ||||||||||
| 54 | |||||||||||
| 55 | =head2 value | ||||||||||
| 56 | |||||||||||
| 57 | This should really have been two methods, but too many other modules | ||||||||||
| 58 | now rely on the fact that this does double duty. As an accessor, this | ||||||||||
| 59 | is the 'raw' value. As a mutator it's the extracted one. | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||
| 62 | |||||||||||
| 63 | 2 | ▶ | sub value { | ||||||||
|
Subroutine
value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 64 | 2 | my $self = shift; | |||||||||
| 65 | 2 | ▶ | $self->{_clean} = shift if defined $_[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 2 | $self->{_raw}; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 1 | ▶ | sub _untaint { | ||||||||
|
Subroutine
_untaint: called CC=2 SCAR=7.0
| |||||||||||
| 70 | 1 | my $self = shift; | |||||||||
| 71 | 1 | my $re = $self->_untaint_re; | |||||||||
| 72 | 1 | ▶ | die unless $self->value =~ $self->_untaint_re; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 1 | $self->value($1); | |||||||||
| 74 | 1 | return 1; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | =head2 re_all / re_none | ||||||||||
| 78 | |||||||||||
| 79 | Regular expressions to match anything, or nothing, untained. These should | ||||||||||
| 80 | only be used if you have already validated your entry in some way that | ||||||||||
| 81 | means you completely trust the data. | ||||||||||
| 82 | |||||||||||
| 83 | =cut | ||||||||||
| 84 | |||||||||||
| 85 | 0 | ▶ | sub re_all { qr/(.*)/ } | ||||||||
|
Subroutine
re_all: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 86 | 0 | ▶ | sub re_none { qr/(?!)/ } | ||||||||
|
Subroutine
re_none: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 87 | |||||||||||
| 88 | =head2 untainted | ||||||||||
| 89 | |||||||||||
| 90 | Are we clean yet? | ||||||||||
| 91 | |||||||||||
| 92 | =cut | ||||||||||
| 93 | |||||||||||
| 94 | 1 | ▶ | sub untainted { shift->{_clean} } | ||||||||
|
Subroutine
untainted: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 95 | |||||||||||
| 96 | 2 | 1; | |||||||||