Querylet/Input.pm

filter: Statementstmt 100% 16 / 16 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 100% 26 / 26 CC 2 SCAR 2.5
CC
2
Cov
100%
import
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« Querylet.pm ↑ Summary Querylet/Output.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Querylet::Input 0.402;
4 # ABSTRACT: generic input handler for Querlet::Query
5  
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #pod =head1 SYNOPSIS
9 #pod
10 #pod This is an abstract base class, meant for subclassing.
11 #pod
12 #pod package Querylet::Input::Term;
13 #pod use base qw(Querylet::Input);
14 #pod
15 #pod sub default_type { 'term' }
16 #pod sub handler { \&from_term }
17 #pod
18 #pod sub from_term {
19 #pod my ($query, $parameter) = @_;
20 #pod
21 #pod print "$parameter: ";
22 #pod my $input = <STDIN>;
23 #pod chomp $input;
24 #pod $query->{input}->{$parameter} = $input;
25 #pod }
26 #pod
27 #pod 1;
28 #pod
29 #pod Then, in a querylet:
30 #pod
31 #pod use Querylet::Input::Term
32 #pod
33 #pod query: SELECT * FROM users WHERE userid = ?
34 #pod
35 #pod input: userid
36 #pod
37 #pod Or, to override the registered type:
38 #pod
39 #pod use Querylet::Input::Term 'stdin';
40 #pod
41 #pod output format: stdin
42 #pod
43 #pod =head1 DESCRIPTION
44 #pod
45 #pod This class provides a simple way to write input handlers for Querylet, mostly
46 #pod by providing an import routine that will register the handler with the
47 #pod type-name requested by the using script.
48 #pod
49 #pod The methods C<default_type> and C<handler> must exist, as described below.
50 #pod
51 #pod =head1 IMPORT
52 #pod
53 #pod Querylet::Input provides an C<import> method that will register the handler
54 #pod when the module is imported. If an argument is given, it will be used as the
55 #pod type name to register. Otherwise, the result of C<default_type> is used.
56 #pod
57 #pod =cut
58  
59 2 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
60 2 my ($class, $type) = @_;
61 2 ▶ $type = $class->default_type unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 1 1 2
62  
63 2 my $handler = $class->handler;
64  
65 2 Querylet::Query->register_input_handler($type => $handler);
66 }
67  
68 #pod =head1 METHODS
69 #pod
70 #pod =over 4
71 #pod
72 #pod =item default_type
73 #pod
74 #pod This method returns the name of the type for which the input handler will be
75 #pod registered if no override is given.
76 #pod
77 #pod =cut
78  
79 1 ▶sub default_type { croak "default_type method unimplemented" }
Subroutine default_type: called CC=1 SCAR=0.0
Pod documented
80  
81 #pod =item handler
82 #pod
83 #pod This method returns a reference to the handler, which will be used to register
84 #pod the handler.
85 #pod
86 #pod =cut
87  
88 1 ▶sub handler { croak "handler method unimplemented" }
Subroutine handler: called CC=1 SCAR=0.0
Pod documented
89  
90 #pod =back
91 #pod
92 #pod =cut
93  
94 1 "I do endeavor to give satisfaction, sir.";
95  
96 __END__
« Querylet.pm ↑ Summary Querylet/Output.pm »