blib/lib/CGI/Untaint/set.pm

filter: Statementstmt 57.8% 11 / 19 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod n/a totaltotal 51.8% 14 / 27 CC 3 SCAR 18.7
CC
3
Cov
48%
_untaint
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 6.5
↑ Summary
1 package CGI::Untaint::set;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use base 'CGI::Untaint::printable';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = 0.01;
9  
10 =head1 NAME
11  
12 CGI::Untaint::set - untaint sets of values
13  
14 =head1 SYNOPSIS
15  
16 use CGI::Untaint;
17 my $handler = CGI::Untaint->new($q->Vars);
18
19 $value = $handler->extract(-as_set => 'films' );
20  
21  
22 =head1 DESCRIPTION
23  
24 Untaints an arrayref (as might be submitted by an HTML multiple select form field, or multiple
25 selections from a checkbox group) as a comma separated string suitable for use as a value for
26 a MySQL (maybe others?) SET column.
27  
28 Values are validated against the L<CGI::Untaint::printable|CGI::Untaint::printable>
29 regex. To validate against a specific set of allowed values, subclass this
30 package and provide a custom C<_untaint_re> method.
31  
32 =cut
33  
34 sub _untaint
35 0 ▶{
Subroutine _untaint: not called CC=3 SCAR=24.8
36 0 my ( $self ) = @_;
37
38 0 my $value = $self->value;
39
40 0 ▶ return $self->SUPER::_untaint unless ref $value;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value 0 0 0
41
42 0 my $re = $self->_untaint_re;
43  
44 0 ▶ $self->value( join ',', map { $_ =~ $re or die; $1 } @$value );
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /$re/ or die 0 0 0
45
46 0 return 1;
47 }
48  
49  
50  
51 =head1 AUTHOR
52  
53 David Baird, C<< <cpan@riverside-cms.co.uk> >>
54  
55 =head1 BUGS
56  
57 Please report any bugs or feature requests to
58 C<bug-cgi-untaint-set@rt.cpan.org>, or through the web interface at
59 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Untaint-set>.
60 I will be notified, and then you'll automatically be notified of progress on
61 your bug as I make changes.
62  
63 =head1 ACKNOWLEDGEMENTS
64  
65 =head1 COPYRIGHT & LICENSE
66  
67 Copyright 2005 David Baird, All Rights Reserved.
68  
69 This program is free software; you can redistribute it and/or modify it
70 under the same terms as Perl itself.
71  
72 =cut
73  
74 2 1; # End of CGI::Untaint::set
↑ Summary