| 1 | package CGI::AppBuilder::Header; | ||
| 2 | |||
| 3 | # Perl standard modules | ||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Getopt::Std; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use POSIX qw(strftime); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use CGI::AppBuilder; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | use CGI::AppBuilder::Message qw(:echo_msg); | ||
| 11 | |||
| 12 | our $VERSION = 0.12; | ||
| 13 | require Exporter; | ||
| 14 | our @ISA = qw(Exporter CGI::AppBuilder); | ||
| 15 | our @EXPORT = qw(); | ||
| 16 | our @EXPORT_OK = qw(build_html_header | ||
| 17 | ); | ||
| 18 | our %EXPORT_TAGS = ( | ||
| 19 | all => [@EXPORT_OK] | ||
| 20 | ); | ||
| 21 | |||
| 22 | =head1 NAME | ||
| 23 | |||
| 24 | CGI::AppBuilder::Header - Configuration initializer | ||
| 25 | |||
| 26 | =head1 SYNOPSIS | ||
| 27 | |||
| 28 | use CGI::AppBuilder::Header; | ||
| 29 | |||
| 30 | my $ab = CGI::AppBuilder::Header->new( | ||
| 31 | 'ifn', 'my_init.cfg', 'opt', 'vhS:a:'); | ||
| 32 | my ($q, $ar, $ar_log) = $ab->start_app($0, \%ARGV); | ||
| 33 | print $ab->disp_form($q, $ar); | ||
| 34 | |||
| 35 | =head1 DESCRIPTION | ||
| 36 | |||
| 37 | This class provides methods for reading and parsing configuration | ||
| 38 | files. | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | =head2 new (ifn => 'file.cfg', opt => 'hvS:') | ||
| 43 | |||
| 44 | This is a inherited method from CGI::AppBuilder. See the same method | ||
| 45 | in CGI::AppBuilder for more details. | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | sub new { | ||
| 50 | my ($s, %args) = @_; | ||
| 51 | return $s->SUPER::new(%args); | ||
| 52 | } | ||
| 53 | |||
| 54 | =head3 build_html_header ($q, $ar) | ||
| 55 | |||
| 56 | Input variables: | ||
| 57 | |||
| 58 | $q - CGI object | ||
| 59 | $ar - array ref for parameters | ||
| 60 | |||
| 61 | Variables used or routines called: | ||
| 62 | |||
| 63 | Debug::EchoMessage | ||
| 64 | echo_msg - echo messages | ||
| 65 | set_param - get a parameter from hash array | ||
| 66 | |||
| 67 | How to use: | ||
| 68 | |||
| 69 | my $ifn = 'myConfig.ini'; | ||
| 70 | my ($q,$ar) = $s->get_inputs($ifn); | ||
| 71 | my $hrf = $self->build_html_header($q, $ar); | ||
| 72 | |||
| 73 | Return: hash array or array ref | ||
| 74 | |||
| 75 | This method performs the following tasks: | ||
| 76 | |||
| 77 | 1) check the following parameters: page_title, page_style, | ||
| 78 | page_meta, page_author, page_target, js_src, | ||
| 79 | 2) writes log records to log files | ||
| 80 | 3) close database connection if it finds DB handler in {dbh} | ||
| 81 | |||
| 82 | =cut | ||
| 83 | |||
| 84 | sub build_html_header { | ||
| 85 | my $s = shift; | ||
| 86 | my ($q, $ar) = @_; | ||
| 87 | |||
| 88 | # 4. start HTML header | ||
| 89 | my $title = $s->set_param('page_title', $ar); | ||
| 90 | $title = "Untitled Page" if ! $title; | ||
| 91 | my $style = $s->set_param('page_style', $ar); | ||
| 92 | $style = '<!-- -->' if ! $style; | ||
| 93 | my $author = $s->set_param('page_author', $ar); | ||
| 94 | $author = 'Hanming.Tu@Premier-Research.COM' if ! $author; | ||
| 95 | my $target = $s->set_param('page_target', $ar); | ||
| 96 | # $target = '_blank' if ! $target; | ||
| 97 | my $js_src = $s->set_param('js_src', $ar); | ||
| 98 | my $yr = strftime "%Y", localtime time; | ||
| 99 | my $meta_txt = $s->set_param('page_meta', $ar); | ||
| 100 | my $mrf = {}; | ||
| 101 | if ($meta_txt) { | ||
| 102 | $mrf = eval $meta_txt; | ||
| 103 | $mrf->{'keywords'} = 'Perl Modules'; | ||
| 104 | $mrf->{'copyright'}= "copyright $yr Hanming Tu"; | ||
| 105 | } else { | ||
| 106 | $mrf = {'keywords'=>'Perl Modules', | ||
| 107 | 'copyright'=>"copyright $yr Hanming Tu"}; | ||
| 108 | } | ||
| 109 | my %ar_hdr = (-title=>$title, -author=>$author, -meta=>$mrf); | ||
| 110 | $ar_hdr{-target}= $target if $target; | ||
| 111 | $ar_hdr{-style} = ($style =~ /^<!--/) ? $style : {'src'=>"$style"}; | ||
| 112 | if ($js_src) { | ||
| 113 | if (index($js_src, ',') > 0) { | ||
| 114 | my @js = map { | ||
| 115 | {-language=>'JavaScript1.2', -src=>$_} | ||
| 116 | } (split /,/, $js_src); | ||
| 117 | $ar_hdr{-script} = \@js; | ||
| 118 | } else { | ||
| 119 | $ar_hdr{-script} = | ||
| 120 | {-language=>'JavaScript1.2', -src=>$js_src}; | ||
| 121 | } | ||
| 122 | } | ||
| 123 | $ar->{html_header} = \%ar_hdr; | ||
| 124 | return wantarray ? %ar_hdr : \%ar_hdr; | ||
| 125 | } | ||
| 126 | |||
| 127 | 1; | ||
| 128 | |||
| 129 | =head1 HISTORY | ||
| 130 | |||
| 131 | =over 4 | ||
| 132 | |||
| 133 | =item * Version 0.10 | ||
| 134 | |||
| 135 | This version extracts the disp_form method from CGI::Getopt class. | ||
| 136 | |||
| 137 | 0.11 Inherited the new constructor from CGI::AppBuilder. | ||
| 138 | |||
| 139 | =item * Version 0.20 | ||
| 140 | |||
| 141 | =cut | ||
| 142 | |||
| 143 | =head1 SEE ALSO (some of docs that I check often) | ||
| 144 | |||
| 145 | Oracle::Loader, Oracle::Trigger, CGI::Getopt, File::Xcopy, | ||
| 146 | CGI::AppBuilder, CGI::AppBuilder::Message, CGI::AppBuilder::Log, | ||
| 147 | CGI::AppBuilder::Config, etc. | ||
| 148 | |||
| 149 | =head1 AUTHOR | ||
| 150 | |||
| 151 | Copyright (c) 2005 Hanming Tu. All rights reserved. | ||
| 152 | |||
| 153 | This package is free software and is provided "as is" without express | ||
| 154 | or implied warranty. It may be used, redistributed and/or modified | ||
| 155 | under the terms of the Perl Artistic License (see | ||
| 156 | http://www.perl.com/perl/misc/Artistic.html) | ||
| 157 | |||
| 158 | =cut | ||
| 159 | |||