lib/CGI/OptimalQuery.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« lib/CGI/OptimalQuery/LoadSearchTool.pm ↑ Summary lib/CGI/OptimalQuery/Base.pm »
1 package CGI::OptimalQuery;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶no warnings qw( uninitialized redefine );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 0 ▶use CGI();
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use CGI::OptimalQuery::SavedSearches();
8  
9 BEGIN {
10 use Exporter ();
11 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
12 $VERSION = '0.30';
13 @ISA = qw(Exporter);
14 #Give a hoot don't pollute, do not export more than needed by default
15 @EXPORT = qw();
16 @EXPORT_OK = qw();
17 %EXPORT_TAGS = ();
18 }
19  
20  
21 # module registry - when loading a sub module, the module CGI param is
22 # consulted, and the value is loaded as a module.
23 our $DEFAULT_MODULE = 'InteractiveQuery2';
24  
25 our %DEFAULT_MODULES = (
26 'SimpleQuery' => 'CGI::OptimalQuery::SimpleQuery',
27 'CustomOutput' => 'CGI::OptimalQuery::CustomOutput',
28 'PrinterFriendly' => 'CGI::OptimalQuery::PrinterFriendly',
29 'CSV' => 'CGI::OptimalQuery::CSV',
30 'InteractiveFilter' => 'CGI::OptimalQuery::InteractiveFilter',
31 'InteractiveQuery' => 'CGI::OptimalQuery::InteractiveQuery',
32 'XML' => 'CGI::OptimalQuery::XML',
33 'JSON' => 'CGI::OptimalQuery::JSON',
34 'InteractiveQuery2' => 'CGI::OptimalQuery::InteractiveQuery2',
35 'InteractiveFilter2' => 'CGI::OptimalQuery::InteractiveFilter2',
36 'ShowColumns' => 'CGI::OptimalQuery::ShowColumns',
37 'InteractiveQuery2Tools' => 'CGI::OptimalQuery::InteractiveQuery2Tools'
38 );
39  
40 sub default_output_handler {
41 print STDOUT @_;
42 return undef;
43 }
44 sub default_error_handler {
45 print STDERR @_;
46 return undef;
47 }
48  
49  
50 # Constructor
51 # my $recset = CGI::OptimalQuery->new(\%schema )
52 # This constructor instantiates the correct class based on the module param.
53 sub new {
54 my $pack = shift;
55 my $schema = $_[0];
56  
57 if ($CGI::OptimalQuery::q) {
58 $$schema{q} = $CGI::OptimalQuery::q;
59 } else {
60 $$schema{q} ||= new CGI();
61 }
62  
63 # if this is a mod_perl query object, turn it into a CGI object
64 if (! $$schema{q}->isa('CGI')) {
65 my @names = $$schema{q}->param();
66 my %params;
67 foreach my $p (@names) {
68 my @v = $$schema{q}->param($p);
69 $params{$p} = \@v;
70 }
71 $$schema{q} = new CGI(\%params);
72 }
73  
74 # set default handlers
75 $$schema{output_handler} ||= \&default_output_handler;
76 $$schema{error_handler} ||= \&default_error_handler;
77 $$schema{httpHeader} ||= \&CGI::header;
78  
79 # find module & class
80 my $module = $$schema{q}->param('module') || $$schema{module} || $DEFAULT_MODULE;
81 my $class = $$schema{modules}{$module} || $DEFAULT_MODULES{$module};
82  
83 # dynamically load class
84 my $rv = eval "require $class";
85 if ($@ =~ /Not\ Found/) { die "Could not find class $class"; }
86 elsif ($@) { die "Compile Error in class $class: $@"; }
87 elsif ($rv != 1) { die "Initialization error in class $class, should return 1"; }
88  
89 # call appropriate constructor
90 return $class->new(@_);
91 }
92  
93 sub escape_js { CGI::OptimalQuery::Base::escape_js(@_); }
94  
95  
96 sub get_saved_search_list {
97 my ($q, $dbh, $userid) = @_;
98 return CGI::OptimalQuery::SavedSearches::get_html($q, $dbh, $userid);
99 }
100  
101  
102 1;
103 __END__
« lib/CGI/OptimalQuery/LoadSearchTool.pm ↑ Summary lib/CGI/OptimalQuery/Base.pm »