Querylet/Output.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/Input.pm ↑ Summary
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::Output 0.402;
4 # ABSTRACT: generic output 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::Output::Tabbed;
13 #pod use base qw(Querylet::Output);
14 #pod
15 #pod sub default_type { 'tabbed' }
16 #pod sub handler { \&as_tabbed }
17 #pod
18 #pod sub as_tabbed {
19 #pod my ($query) = @_;
20 #pod my @output;
21 #pod push @output, join("\t", @{$query->columns});
22 #pod push @output, join("\t", @{$_{@{$query->colummns}}}) for @{$query->results};
23 #pod return join("\n", @output);
24 #pod }
25 #pod
26 #pod 1;
27 #pod
28 #pod Then, in a querylet:
29 #pod
30 #pod use Querylet::Output::Tabbed;
31 #pod
32 #pod output format: tabbed
33 #pod
34 #pod Or, to override the registered type:
35 #pod
36 #pod use Querylet::Output::Tabbed 'tsv';
37 #pod
38 #pod output format: tsv
39 #pod
40 #pod =head1 DESCRIPTION
41 #pod
42 #pod This class provides a simple way to write output handlers for Querylet, mostly
43 #pod by providing an import routine that will register the handler with the
44 #pod type-name requested by the using script.
45 #pod
46 #pod The methods C<default_type> and C<handler> must exist, as described below.
47 #pod
48 #pod =head1 IMPORT
49 #pod
50 #pod Querylet::Output provides an C<import> method that will register the handler
51 #pod when the module is imported. If an argument is given, it will be used as the
52 #pod type name to register. Otherwise, the result of C<default_type> is used.
53 #pod
54 #pod =cut
55  
56 2 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
57 2 my ($class, $type) = @_;
58 2 ▶ $type = $class->default_type unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 1 1 2
59  
60 2 my $handler = $class->handler;
61  
62 2 Querylet::Query->register_output_handler($type => $handler);
63 }
64  
65 #pod =head1 METHODS
66 #pod
67 #pod =over 4
68 #pod
69 #pod =item default_type
70 #pod
71 #pod This method returns the name of the type for which the output handler will be
72 #pod registered if no override is given.
73 #pod
74 #pod =cut
75  
76 1 ▶sub default_type { croak "default_type method unimplemented" }
Subroutine default_type: called CC=1 SCAR=0.0
Pod documented
77  
78 #pod =item handler
79 #pod
80 #pod This method returns a reference to the handler, which will be used to register
81 #pod the handler.
82 #pod
83 #pod =cut
84  
85 1 ▶sub handler { croak "handler method unimplemented" }
Subroutine handler: called CC=1 SCAR=0.0
Pod documented
86  
87 #pod =back
88 #pod
89 #pod =cut
90  
91 1 "I do endeavor to give satisfaction, sir.";
92  
93 __END__
« Querylet/Input.pm ↑ Summary