File Coverage

blib/lib/Querylet/Input.pm
Criterion Covered Total %
statement 15 15 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 25 25 100.0


line stmt bran cond sub pod time code
1 1     1   800 use strict;
  1         2  
  1         25  
2 1     1   4 use warnings;
  1         2  
  1         29  
3             package Querylet::Input 0.402;
4             # ABSTRACT: generic input handler for Querlet::Query
5              
6 1     1   5 use Carp;
  1         1  
  1         154  
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 = ;
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 and C must exist, as described below.
50             #pod
51             #pod =head1 IMPORT
52             #pod
53             #pod Querylet::Input provides an C 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 is used.
56             #pod
57             #pod =cut
58              
59             sub import {
60 2     2   1632 my ($class, $type) = @_;
61 2 100       8 $type = $class->default_type unless $type;
62              
63 2         7 my $handler = $class->handler;
64              
65 2         18 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     1 1 234 sub default_type { croak "default_type method unimplemented" }
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     1 1 732 sub handler { croak "handler method unimplemented" }
89              
90             #pod =back
91             #pod
92             #pod =cut
93              
94             "I do endeavor to give satisfaction, sir.";
95              
96             __END__