| 1 | package CGI::AppBuilder::Frame; | ||
| 2 | |||
| 3 | # Perl standard modules | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use Getopt::Std; | ||
| 7 | use POSIX qw(strftime); | ||
| 8 | use Carp; | ||
| 9 | |||
| 10 | our $VERSION = 1.001; | ||
| 11 | require Exporter; | ||
| 12 | our @ISA = qw(Exporter CGI::AppBuilder); | ||
| 13 | our @EXPORT = qw(); | ||
| 14 | our @EXPORT_OK = qw(frame_set frameset | ||
| 15 | ); | ||
| 16 | our %EXPORT_TAGS = ( | ||
| 17 | frame => [qw(frame_set frameset)], | ||
| 18 | all => [@EXPORT_OK] | ||
| 19 | ); | ||
| 20 | |||
| 21 | use CGI::AppBuilder; | ||
| 22 | use CGI::AppBuilder::Message qw(:all); | ||
| 23 | use CGI::AppBuilder::Table qw(:all); | ||
| 24 | |||
| 25 | =head1 NAME | ||
| 26 | |||
| 27 | CGI::AppBuilder::Frame - Configuration initializer | ||
| 28 | |||
| 29 | =head1 SYNOPSIS | ||
| 30 | |||
| 31 | use CGI::AppBuilder::Frame; | ||
| 32 | |||
| 33 | my $ab = CGI::AppBuilder::Frame->new( | ||
| 34 | 'ifn', 'my_init.cfg', 'opt', 'vhS:a:'); | ||
| 35 | my ($q, $ar, $ar_log) = $ab->start_app($0, \%ARGV); | ||
| 36 | print $ab->disp_form($q, $ar); | ||
| 37 | |||
| 38 | =head1 DESCRIPTION | ||
| 39 | |||
| 40 | This class provides methods for reading and parsing configuration | ||
| 41 | files. | ||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | =head2 new (ifn => 'file.cfg', opt => 'hvS:') | ||
| 46 | |||
| 47 | This is a inherited method from CGI::AppBuilder. See the same method | ||
| 48 | in CGI::AppBuilder for more details. | ||
| 49 | |||
| 50 | =cut | ||
| 51 | |||
| 52 | sub new { | ||
| 53 | my ($s, %args) = @_; | ||
| 54 | return $s->SUPER::new(%args); | ||
| 55 | } | ||
| 56 | |||
| 57 | =head2 frame_set ($q, $fr, $pr) | ||
| 58 | |||
| 59 | Input variables: | ||
| 60 | |||
| 61 | $fr - frame set definiton array reference. The $fr contains two | ||
| 62 | elements [$hr, $ar]: | ||
| 63 | $hr - a hash ref containing the frame set attributes | ||
| 64 | $ar - a array ref containing hash references defining each | ||
| 65 | frames in the frame set. | ||
| 66 | $pr - tag attribute array ref. It contains three elements: | ||
| 67 | class - CSS class name | ||
| 68 | attr - attribute string such as 'width=5 onChange=js_func' | ||
| 69 | hr - hash ref with key and value pairs. This will be obtained | ||
| 70 | from $fr for each frame set and frame. | ||
| 71 | pretty - whether to add line breaks | ||
| 72 | |||
| 73 | Variables used or methods called: | ||
| 74 | |||
| 75 | CGI::AppBuilder::Table | ||
| 76 | html_tag - generate HTML tags | ||
| 77 | CGI::AppBuilder::Message | ||
| 78 | echo_msg - display message | ||
| 79 | |||
| 80 | How to use: | ||
| 81 | |||
| 82 | The following shows how to define the frame array ($fr): | ||
| 83 | |||
| 84 | +-+----+ The following defines the left layout: | ||
| 85 | | | T | | ||
| 86 | | +----+ [{cols=>"150,*"},[ | ||
| 87 | | | | {src=>"left.htm",name=>"L"}, | ||
| 88 | |L| C | [{rows=>"100,*,50"},[ | ||
| 89 | | | | {src=>"top.htm",name=>"T"}, | ||
| 90 | | |----| {src=>"main.htm",name=>"C"}, | ||
| 91 | | | B | {src=>"bottom.htm",name=>"B"}]]] | ||
| 92 | +-+----+ ] | ||
| 93 | |||
| 94 | In YAML, here is how it looks like: | ||
| 95 | |||
| 96 | --- | ||
| 97 | cols: 150,\* | ||
| 98 | - src: left.htm | ||
| 99 | name: L | ||
| 100 | - rows: 100,\*,50 | ||
| 101 | - src: top.htm | ||
| 102 | name: T | ||
| 103 | - src: main.htm | ||
| 104 | name: C | ||
| 105 | - src: bottom.htm | ||
| 106 | name: B | ||
| 107 | ... | ||
| 108 | |||
| 109 | +-+------+ The following defines the left layout: | ||
| 110 | | | T | | ||
| 111 | | +----+-+ [{cols=>"150,*"},[ | ||
| 112 | | | | | {src=>"left.htm",name=>"L"}, | ||
| 113 | |L| C |R| [{rows=>"100,*,50"},[ | ||
| 114 | | | | | {src=>"top.htm",name=>"T"}, | ||
| 115 | | | | | [{cols=>"*,100"},[ | ||
| 116 | | |----+-+ {src=>"main.htm",name=>"C"}, | ||
| 117 | | | | {src=>"right.htm",name=>"R"}] ] ], | ||
| 118 | | | B | {src=>"bottom.htm",name=>"B"}]] | ||
| 119 | +-+----+-+ ] | ||
| 120 | |||
| 121 | In YAML, here is how it looks like: | ||
| 122 | |||
| 123 | --- | ||
| 124 | cols: 150,\* | ||
| 125 | - src: left.htm | ||
| 126 | name: L | ||
| 127 | - rows: 100,\*,50 | ||
| 128 | - src: top.htm | ||
| 129 | name: T | ||
| 130 | - cols: \*,100 | ||
| 131 | - src: main.htm | ||
| 132 | name: C | ||
| 133 | - src: right.htm | ||
| 134 | name: R | ||
| 135 | - src: bottom.htm | ||
| 136 | name: B | ||
| 137 | ... | ||
| 138 | |||
| 139 | Here is the testing codes: | ||
| 140 | |||
| 141 | my $fr = [{cols=>"150,*"},[ | ||
| 142 | {src=>"left.htm",name=>"L"}, | ||
| 143 | [{rows=>"100,*,50"},[ | ||
| 144 | {src=>"top.htm",name=>"T"}, | ||
| 145 | {src=>"main.htm",name=>"C"}, | ||
| 146 | {src=>"bottom.htm",name=>"B"}] | ||
| 147 | ]] | ||
| 148 | ]; | ||
| 149 | my $pr = {pretty=>1}; | ||
| 150 | print $obj->frame_set($fr,$pr); | ||
| 151 | # the following is the result: | ||
| 152 | |||
| 153 | <FRAMESET cols='150,*'> | ||
| 154 | <FRAME src='left.htm' name='L'> | ||
| 155 | <FRAMESET rows='100,*,50'> | ||
| 156 | <FRAME src='top.htm' name='T'> | ||
| 157 | <FRAME src='main.htm' name='C'> | ||
| 158 | <FRAME src='bottom.htm' name='B'> | ||
| 159 | </FRAMESET> | ||
| 160 | </FRAMESET> | ||
| 161 | |||
| 162 | $pr->{_frameset_count} = 0; # reset frame set counter | ||
| 163 | my $f2 = [ {cols=>"150,*"},[ | ||
| 164 | {src=>"left.htm",name=>"L"}, | ||
| 165 | [{rows=>"100,*,50"},[ | ||
| 166 | {src=>"top.htm",name=>"T"}, | ||
| 167 | [{cols=>"*,100"},[ | ||
| 168 | {src=>"main.htm",name=>"C"}, | ||
| 169 | {src=>"right.htm",name=>"R"}] | ||
| 170 | ], | ||
| 171 | {src=>"bottom.htm",name=>"B"}] | ||
| 172 | ]] | ||
| 173 | ]; | ||
| 174 | print $obj->frame_set($f2,$pr); | ||
| 175 | # the following is the result: | ||
| 176 | |||
| 177 | <FRAMESET cols='150,*'> | ||
| 178 | <FRAME src='left.htm' name='L'> | ||
| 179 | <FRAMESET rows='100,*,50'> | ||
| 180 | <FRAME src='top.htm' name='T'> | ||
| 181 | <FRAMESET cols='*,100'> | ||
| 182 | <FRAME src='main.htm' name='C'> | ||
| 183 | <FRAME src='right.htm' name='R'> | ||
| 184 | </FRAMESET> | ||
| 185 | <FRAME src='bottom.htm' name='B'> | ||
| 186 | </FRAMESET> | ||
| 187 | </FRAMESET> | ||
| 188 | |||
| 189 | Return: HTML codes. | ||
| 190 | |||
| 191 | This method generates HTML codes based on the information provided. | ||
| 192 | This method is also called <I>frameset</I>. | ||
| 193 | |||
| 194 | =cut | ||
| 195 | |||
| 196 | sub frameset { | ||
| 197 | my $s = shift; | ||
| 198 | return $s->frame_set(@_); | ||
| 199 | } | ||
| 200 | |||
| 201 | sub frame_set { | ||
| 202 | my $s = shift; | ||
| 203 | my ($q, $fr, $pr) = @_; | ||
| 204 | if ($fr && ref($fr) !~ /ARRAY/) { | ||
| 205 | $s->echo_msg(ref($fr) . " Frame set is not in ARRAY",1); | ||
| 206 | return; | ||
| 207 | } | ||
| 208 | $pr = {} if ! defined($pr) || ! $pr; | ||
| 209 | my ($p, $v) = (@$fr); | ||
| 210 | $s->echo_msg("Frame set attribute is not defined.", 2) | ||
| 211 | if ref($p) !~ /HASH/; | ||
| 212 | $pr->{hr} = $p; | ||
| 213 | ++$pr->{_frameset_count}; | ||
| 214 | my ($t,$idt) = ("", " "); | ||
| 215 | $t .= $idt x ($pr->{_frameset_count}-1) if $pr->{_frameset_count}>1; | ||
| 216 | $t .= $s->html_tag('frameset',$pr); | ||
| 217 | # $t .= "\n" if exists $pr->{pretty} && $pr->{pretty}; | ||
| 218 | foreach my $k (@$v) { | ||
| 219 | $pr->{hr} = $k; | ||
| 220 | if (ref($k) =~ /ARRAY/) { | ||
| 221 | $t .= $s->frame_set($q,$k,$pr); | ||
| 222 | --$pr->{_frameset_count}; | ||
| 223 | next; | ||
| 224 | } | ||
| 225 | $s->echo_msg("Frame attribute is not defined.", 2) | ||
| 226 | if ref($k) !~ /HASH/; | ||
| 227 | $t .= $idt x $pr->{_frameset_count}; | ||
| 228 | $t .= $s->html_tag('frame',$pr); | ||
| 229 | } | ||
| 230 | if ($pr->{_frameset_count} > 1) { | ||
| 231 | $t .= ($idt x ($pr->{_frameset_count}-1)) . "</FRAMESET>\n"; | ||
| 232 | } else { | ||
| 233 | $t .= "</FRAMESET>\n"; | ||
| 234 | } | ||
| 235 | return $t; | ||
| 236 | } | ||
| 237 | |||
| 238 | 1; | ||
| 239 | |||
| 240 | =head1 HISTORY | ||
| 241 | |||
| 242 | =over 4 | ||
| 243 | |||
| 244 | =item * Version 0.10 | ||
| 245 | |||
| 246 | This version includes the frame_set method. | ||
| 247 | |||
| 248 | =item * Version 0.20 | ||
| 249 | |||
| 250 | =cut | ||
| 251 | |||
| 252 | =head1 SEE ALSO (some of docs that I check often) | ||
| 253 | |||
| 254 | Oracle::Loader, Oracle::Trigger, CGI::Getopt, File::Xcopy, | ||
| 255 | CGI::AppBuilder, CGI::AppBuilder::Message, CGI::AppBuilder::Log, | ||
| 256 | CGI::AppBuilder::Config, etc. | ||
| 257 | |||
| 258 | =head1 AUTHOR | ||
| 259 | |||
| 260 | Copyright (c) 2005 Hanming Tu. All rights reserved. | ||
| 261 | |||
| 262 | This package is free software and is provided "as is" without express | ||
| 263 | or implied warranty. It may be used, redistributed and/or modified | ||
| 264 | under the terms of the Perl Artistic License (see | ||
| 265 | http://www.perl.com/perl/misc/Artistic.html) | ||
| 266 | |||
| 267 | =cut | ||
| 268 |