blib/lib/Froody/Argument.pm

filter: Statementstmt 86.2% 25 / 29 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 100% 3 / 3 totaltotal 83.6% 41 / 49 CC 5 SCAR 6.7
CC
5
Cov
84%
process
3.1
type
2.0
_types
2.0
CRAP 2.0
« blib/lib/Froody/Walker/Driver.pm ↑ Summary blib/lib/Froody/Server/CGI.pm »
1 package Froody::Argument;
2 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 18 ▶use Module::Pluggable search_path => 'Froody::Argument',
Subroutine BEGIN: called CC=1 SCAR=0.0
6 inner => 1,
7 18 sub_name => 'argument_types';
8
9 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
10 0 Froody::Error->throw('froody.unimplemented', "Beat someone for not finishing things");
11 }
12  
13 18 our $types;
14  
15 148 ▶sub _types {
Subroutine _types: called CC=2 SCAR=6.9
16 148 my $self = shift;
17  
18 148 ▶ return $types if defined $types;
Branch: 1 branch
BranchTrueFalseTotal
if defined $Froody::Argument::types 130 18 148
19
20 18 return $types = { map { _register_type_names($_) } $self->argument_types };
21 }
22  
23 108 ▶sub _register_type_names {
Subroutine _register_type_names: called CC=2 SCAR=6.9
24 108 my $handler = shift;
25 108 ▶ unless ($handler->can('type')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($handler->can("type")) 6 102 108
26 6 return ();
27 }
28 102 return map { $_ => $handler } $handler->type;
29 }
30  
31 18 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
32 18 __PACKAGE__->_types();
33 }
34  
35  
36 32 ▶sub process {
Subroutine process: called CC=3 SCAR=11.4
Pod documented
37 32 my ($class, $type, $param, $check) = @_;
38
39 32 ▶ my $validator = $class->_types()->{$type}
Branch: 1 branch
BranchTrueFalseTotal
my $validator = $class->_types->{$type} or return $param 32 0 32
40 or return $param;
41
42 32 ▶ my $f = $validator->can("process")
Branch: 1 branch
BranchTrueFalseTotal
my $f = $validator->can("process") or return $param 32 0 32
43 or return $param;
44  
45 32 $f->($class, $param, $check);
46 }
47  
48 0 ▶sub add_path {
Subroutine add_path: not called CC=1 SCAR=6.9
Pod documented
49 0 my ($class, $path) = @_;
50  
51 0 $types = undef;
52 0 $class->SUPER::search_path(add => $path);
53 }
54  
55 18 1;
56  
57 =head1 NAME
58  
59 Froody::Argument - Froody argument type handler
60  
61 =head1 DESCRIPTION
62  
63 If you want to register a new type handler with Froody, create a
64 module in the Froody::Argument::* namespace. It will automagically be
65 registered with the type handler framework.
66  
67 =head1 METHODS
68  
69 Froody::Argument plugins are required to implement the following
70 methods:
71  
72 =over
73  
74 =item type
75  
76 The name of the type
77  
78 =item process($param_value, $check_callback)
79  
80 Handles validation for a given type. If there's a possiblity of
81 failure, the C<$check_callback> should be called. It takes two
82 arguments - a test value (a true value for passing), and
83 a message which describes how the value failed type validation.
84  
85 =item add_path($module name)
86  
87 Register a new set of type handlers under the path indicated by
88 C<$module name>.
89  
90 =back
91  
92 =head1 AUTHORS
93  
94 Copyright Fotango 2006. All rights reserved.
95  
96 Please see the main L<Froody> documentation for details of who has worked
97 on this project.
98  
99 This module is free software; you can redistribute it and/or modify it under
100 the same terms as Perl itself.
101  
102 =cut
« blib/lib/Froody/Walker/Driver.pm ↑ Summary blib/lib/Froody/Server/CGI.pm »