File Coverage

lib/CGI/OptimalQuery.pm
Criterion Covered Total %
statement 26 54 48.1
branch 0 10 0.0
condition 0 13 0.0
subroutine 8 13 61.5
pod 1 3 33.3
total 35 93 37.6


line stmt bran cond sub pod time code
1             package CGI::OptimalQuery;
2              
3 8     8   6157 use strict;
  8         15  
  8         181  
4 8     8   31 use warnings;
  8         12  
  8         176  
5 8     8   33 no warnings qw( uninitialized redefine );
  8         11  
  8         213  
6 8     8   4704 use CGI();
  8         172476  
  8         182  
7 8     8   2663 use CGI::OptimalQuery::SavedSearches();
  8         20  
  8         241  
8              
9             BEGIN {
10 8     8   55 use Exporter ();
  8         15  
  8         158  
11 8     8   32 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  8         10  
  8         635  
12 8     8   24 $VERSION = '0.26';
13 8         160 @ISA = qw(Exporter);
14             #Give a hoot don't pollute, do not export more than needed by default
15 8         22 @EXPORT = qw();
16 8         13 @EXPORT_OK = qw();
17 8         3317 %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 0     0 1   my $pack = shift;
46 0           my $schema = $_[0];
47              
48 0 0         if ($CGI::OptimalQuery::q) {
49 0           $$schema{q} = $CGI::OptimalQuery::q;
50             } else {
51 0   0       $$schema{q} ||= new CGI();
52             }
53              
54             # if this is a mod_perl query object, turn it into a CGI object
55 0 0         if (! $$schema{q}->isa('CGI')) {
56 0           my @names = $$schema{q}->param();
57 0           my %params;
58 0           foreach my $p (@names) {
59 0           my @v = $$schema{q}->param($p);
60 0           $params{$p} = \@v;
61             }
62 0           $$schema{q} = new CGI(\%params);
63             }
64              
65             # set default handlers
66 0   0 0     $$schema{output_handler} ||= sub { print @_ };
  0            
67 0   0 0     $$schema{error_handler} ||= sub { print STDERR @_; 0; };
  0            
  0            
68              
69             # find module & class
70 0   0       my $module = $$schema{q}->param('module') || $$schema{module} || $DEFAULT_MODULE;
71 0   0       my $class = $$schema{modules}{$module} || $DEFAULT_MODULES{$module};
72              
73             # dynamically load class
74 0           my $rv = eval "require $class";
75 0 0         if ($@ =~ /Not\ Found/) { die "Could not find class $class"; }
  0 0          
    0          
76 0           elsif ($@) { die "Compile Error in class $class: $@"; }
77 0           elsif ($rv != 1) { die "Initialization error in class $class, should return 1"; }
78              
79             # call appropriate constructor
80 0           return $class->new(@_);
81             }
82              
83 0     0 0   sub escape_js { CGI::OptimalQuery::Base::escape_js(@_); }
84              
85              
86             sub get_saved_search_list {
87 0     0 0   my ($q, $dbh, $userid) = @_;
88 0           return CGI::OptimalQuery::SavedSearches::get_html($q, $dbh, $userid);
89             }
90              
91              
92             1;
93             __END__