Basic/Four.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 64 CC 1 SCAR 6.9
CC
1
Cov
0%
cgiapp_get_query
2.0
cgiapp_init
2.0
setup
2.0
CRAP 2.0
1 package CGI::Application::Demo::Basic::Four;
2  
3 # Documentation:
4 # POD-style documentation is at the end. Extract it with pod2html.*.
5 #
6 # Note:
7 # o tab = 4 spaces || die
8 #
9 # Author:
10 # Ron Savage <ron@savage.net.au>
11 # http://savage.net.au/index.html
12  
13 use base 'CGI::Application';
14 use strict;
15 use warnings;
16  
17 require 5.005_62;
18  
19 use CGI::Application::Demo::Basic::Util::Config;
20  
21 use CGI::Simple;
22  
23 use DBI;
24  
25 our $VERSION = '1.06';
26  
27 # -----------------------------------------------
28  
29 sub cgiapp_get_query
30 {
31 my($self) = @_;
32  
33 return CGI::Simple -> new;
34  
35 } # End of cgiapp_get_query.
36  
37 # -----------------------------------------------
38  
39 sub cgiapp_init
40 {
41 my($self) = @_;
42 my($config) = CGI::Application::Demo::Basic::Util::Config -> new('four.conf') -> config;
43  
44 $self -> param(config => $config);
45 $self -> param(dbh => DBI -> connect($$config{'dsn'}, $$config{'username'}, $$config{'password'}) );
46 $self -> param(tmpl_path => $$config{'tmpl_path'});
47  
48 } # End of cgiapp_init.
49  
50 # -----------------------------------------------
51  
52 sub setup
53 {
54 my($self) = @_;
55  
56 $self -> run_modes(start => \&start);
57 $self -> tmpl_path($self -> param('tmpl_path') );
58  
59 } # End of setup.
60  
61 # -----------------------------------------------
62  
63 sub start
64 {
65 my($self) = shift;
66 my($config) = $self -> param('config');
67 my($template) = $self -> load_tmpl($$config{'tmpl_name'});
68 my(@content) =
69 (
70 'Time: ' . scalar localtime,
71 'URL: ' . $self -> query -> url,
72 'PathInfo: ' . $self -> query -> path_info,
73 "CGI::Simple V $CGI::Simple::VERSION",
74 "DBI V $DBI::VERSION",
75 'Template name: ' . $$config{'tmpl_name'},
76 'Template path: ' . $self -> param('tmpl_path'),
77 'dbh: ' . $self -> param('dbh'),
78 );
79  
80 # Test DBI.
81  
82 my($sql) = 'select faculty_id, faculty_name from faculty';
83 my($sth) = $self -> param('dbh') -> prepare($sql);
84  
85 $sth -> execute;
86  
87 my($data);
88  
89 while ($data = $sth -> fetch)
90 {
91 push @content, qq|<span class="$$config{'css_class'}">$$data[0]: $$data[1]</span>|;
92 }
93  
94 $template -> param(css_url => $$config{'css_url'});
95 $template -> param(li_loop => [map{ {item => $_} } @content]);
96 $template -> param(title => __PACKAGE__);
97  
98 $self -> param('dbh') -> disconnect;
99  
100 return $template -> output;
101  
102 } # End of start.
103  
104 # -----------------------------------------------
105  
106 1;