blib/lib/CGI/OptimalQuery.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 18 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 99 SCAR 37.4
CC
6
Cov
0%
new
42.0
BEGIN
2.0
escape_js
2.0
CRAP 42.0
1 package CGI::OptimalQuery;
2  
3 use strict;
4 use warnings;
5 no warnings qw( uninitialized redefine );
6 use CGI();
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.26';
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  
41 # Constructor
42 # my $recset = CGI::OptimalQuery->new(\%schema )
43 # This constructor instantiates the correct class based on the module param.
44 sub new {
45 my $pack = shift;
46 my $schema = $_[0];
47  
48 if ($CGI::OptimalQuery::q) {
49 $$schema{q} = $CGI::OptimalQuery::q;
50 } else {
51 $$schema{q} ||= new CGI();
52 }
53  
54 # if this is a mod_perl query object, turn it into a CGI object
55 if (! $$schema{q}->isa('CGI')) {
56 my @names = $$schema{q}->param();
57 my %params;
58 foreach my $p (@names) {
59 my @v = $$schema{q}->param($p);
60 $params{$p} = \@v;
61 }
62 $$schema{q} = new CGI(\%params);
63 }
64  
65 # set default handlers
66 $$schema{output_handler} ||= sub { print @_ };
67 $$schema{error_handler} ||= sub { print STDERR @_; 0; };
68  
69 # find module & class
70 my $module = $$schema{q}->param('module') || $$schema{module} || $DEFAULT_MODULE;
71 my $class = $$schema{modules}{$module} || $DEFAULT_MODULES{$module};
72  
73 # dynamically load class
74 my $rv = eval "require $class";
75 if ($@ =~ /Not\ Found/) { die "Could not find class $class"; }
76 elsif ($@) { die "Compile Error in class $class: $@"; }
77 elsif ($rv != 1) { die "Initialization error in class $class, should return 1"; }
78  
79 # call appropriate constructor
80 return $class->new(@_);
81 }
82  
83 sub escape_js { CGI::OptimalQuery::Base::escape_js(@_); }
84  
85  
86 sub get_saved_search_list {
87 my ($q, $dbh, $userid) = @_;
88 return CGI::OptimalQuery::SavedSearches::get_html($q, $dbh, $userid);
89 }
90  
91  
92 1;
93 __END__