line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
CGI::Widget::Tabs::Heading - Create OO tab headings for CGI::Widget::Tabs objects |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSIS |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
None. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
This module is designed to work with CGI::Widget::Tabs. You can not use this module |
14
|
|
|
|
|
|
|
in a standalone fashion. Look at the CGI::Widget::Tabs documentation for more info. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 PUBLIC INTERFACE |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head2 Public Class Interface |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
package CGI::Widget::Tabs::Heading; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# pragmata |
27
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
79
|
|
28
|
2
|
|
|
2
|
|
10
|
use vars qw/$VERSION/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
83
|
|
29
|
|
|
|
|
|
|
# Standard Perl Library and CPAN modules |
30
|
2
|
|
|
2
|
|
9
|
use HTML::Entities; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
884
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$VERSION = "1.00"; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head3 new |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
new($proto) |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new { |
41
|
24
|
|
|
24
|
1
|
28
|
my $proto = shift; |
42
|
24
|
|
33
|
|
|
88
|
my $class = ref($proto) || $proto; |
43
|
24
|
|
|
|
|
34
|
my $self = {}; |
44
|
24
|
|
|
|
|
58
|
bless ($self, $class); |
45
|
24
|
|
|
|
|
50
|
$self->raw(0); # by default text is HTML escaped |
46
|
24
|
|
|
|
|
55
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 Public Object Interface |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
These methods define the properties and behaviour of the object oriented |
53
|
|
|
|
|
|
|
headings. Each OO heading can be tailored to specific requirements. Fresh new |
54
|
|
|
|
|
|
|
OO headings are created by using the heading() method on a CGI::Widget::Tabs |
55
|
|
|
|
|
|
|
object. Existing OO headings are returned by the headings() method. In the |
56
|
|
|
|
|
|
|
tabs-demo.pl file OO headings are used as well. So look at that demo for a |
57
|
|
|
|
|
|
|
real life example. Example: |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# create, append and return a new heading |
60
|
|
|
|
|
|
|
my $h = $tab->heading(); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# focus on the third heading |
63
|
|
|
|
|
|
|
my $h = ($tab->headings)[2]; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
The properties and behaviour of an OO heading can be set with the following |
67
|
|
|
|
|
|
|
methods: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head3 class |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
class(STRING) |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Overrides the widget's CSS class for this heading. This is useful if you have |
74
|
|
|
|
|
|
|
a specific heading (e.g. "Maintenance") which always needs it's own private |
75
|
|
|
|
|
|
|
mark up. If the optional argument STRING is given, the class for this heading |
76
|
|
|
|
|
|
|
is set. Otherwise it is retrieved. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub class { |
81
|
|
|
|
|
|
|
# |
82
|
|
|
|
|
|
|
# Specific heading class overriding the default widget class |
83
|
|
|
|
|
|
|
# |
84
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
85
|
0
|
0
|
|
|
|
0
|
if ( @_ ) { |
86
|
0
|
|
|
|
|
0
|
$self->{class} = shift; |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
0
|
return $self->{class}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head3 key |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
key(STRING) |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Sets/returns the value to use for this heading in the CGI query param list. |
96
|
|
|
|
|
|
|
This is similar to the use of keys in key/value pairs in the headings() |
97
|
|
|
|
|
|
|
method. The goal is to simplify programming logic and shorten the URL's. (See |
98
|
|
|
|
|
|
|
the headings() method elsewhere in this document for further explanation). |
99
|
|
|
|
|
|
|
Example: |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# display the full heading... |
102
|
|
|
|
|
|
|
# ...but use a small key as query param value |
103
|
|
|
|
|
|
|
$h->text("Remote Configurations"); |
104
|
|
|
|
|
|
|
$h->key("rc"); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
In contrast to the use of key/value pairs, CGI::Widget::Tabs knows that this |
107
|
|
|
|
|
|
|
is a key and not a value. After all, you are using the key() method, right? |
108
|
|
|
|
|
|
|
Consequently you don't need the prepend the key with a hyphen ("-"). You may |
109
|
|
|
|
|
|
|
consider using a hyphen for your keys nevertheless. It will lead to more |
110
|
|
|
|
|
|
|
transparent code. Observe how the snippet from above with a prepended "-" |
111
|
|
|
|
|
|
|
will later on result in the following check: |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
if ( $tab->active eq "-rc" ) { # clearly we are using keys .... |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Consider this a mild suggestion. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub key { |
120
|
|
|
|
|
|
|
# |
121
|
|
|
|
|
|
|
# The key to identify this heading with |
122
|
|
|
|
|
|
|
# |
123
|
16
|
|
|
16
|
1
|
35
|
my $self = shift; |
124
|
16
|
100
|
|
|
|
33
|
if ( @_ ) { |
125
|
13
|
|
|
|
|
28
|
$self->{key} = shift; |
126
|
|
|
|
|
|
|
} |
127
|
16
|
|
|
|
|
44
|
return $self->{key}; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head3 raw |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
raw(BOOLEAN) |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
The heading text will normally be HTML encoded. If you wish you can use |
136
|
|
|
|
|
|
|
hard coded HTML. To avoid escaping this HTML, you need to set raw() to a |
137
|
|
|
|
|
|
|
logical TRUE. This is usually a 1 (one). Setting it to FALSE (usually a 0) |
138
|
|
|
|
|
|
|
will re-enable HTML encoding. The optional argument BOOLEAN can be any |
139
|
|
|
|
|
|
|
argument evaluating to a logical value. Setting raw() will not take effect |
140
|
|
|
|
|
|
|
until the widget is rendered. So it does not matter when you set it, as long |
141
|
|
|
|
|
|
|
as you haven't rendered the widget. Examples: |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# HTML encoded |
144
|
|
|
|
|
|
|
$h1->text("Names A > L"); |
145
|
|
|
|
|
|
|
$h2->text("Names M < Z"); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# Raw |
148
|
|
|
|
|
|
|
$h1->text("Names A > L"); |
149
|
|
|
|
|
|
|
$h1->raw(1); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
$h2->text("Names M < Z"); |
152
|
|
|
|
|
|
|
$h2->raw(1); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# get the encoding setting of the fourth element |
155
|
|
|
|
|
|
|
my $h = ($tab->headings)[3]; |
156
|
|
|
|
|
|
|
my $raw = $h->raw; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub raw { |
162
|
|
|
|
|
|
|
# |
163
|
|
|
|
|
|
|
# Raw or HTML escaped? |
164
|
|
|
|
|
|
|
# |
165
|
50
|
|
|
50
|
1
|
91
|
my $self = shift; |
166
|
50
|
|
|
|
|
55
|
my $arg = shift; |
167
|
|
|
|
|
|
|
|
168
|
50
|
100
|
|
|
|
100
|
if ( defined $arg ) { |
169
|
24
|
50
|
|
|
|
72
|
$self->{raw} = $arg ? 1 : 0; |
170
|
|
|
|
|
|
|
} |
171
|
50
|
|
|
|
|
103
|
return $self->{raw}; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head3 text |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
text(STRING) |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Sets/returns the heading text. If the optional argument STRING is given, the |
180
|
|
|
|
|
|
|
text will be set otherwise it will be returned. The heading text will be HTML |
181
|
|
|
|
|
|
|
encoded unless explicitely told otherwise (see: raw()). Examples: |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# set heading text for the first two headings |
184
|
|
|
|
|
|
|
($tab->headings)[0]->text("Names A > L"); |
185
|
|
|
|
|
|
|
($tab->headings)[1]->text("Names M < Z"); |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
# get the text of the 4th heading |
188
|
|
|
|
|
|
|
my $text = ($tab->headings)[3]->text; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub text { |
194
|
|
|
|
|
|
|
# |
195
|
|
|
|
|
|
|
# Text to be displayed |
196
|
|
|
|
|
|
|
# |
197
|
26
|
|
|
26
|
1
|
53
|
my $self = shift; |
198
|
26
|
|
|
|
|
35
|
my $text; |
199
|
|
|
|
|
|
|
|
200
|
26
|
100
|
|
|
|
54
|
if ( @_ ) { |
201
|
24
|
|
|
|
|
42
|
$self->{text} = shift; |
202
|
|
|
|
|
|
|
} |
203
|
26
|
50
|
|
|
|
47
|
if ( $self->raw ) { |
204
|
0
|
|
|
|
|
0
|
$text = $self->{text}; |
205
|
|
|
|
|
|
|
} else { |
206
|
26
|
|
|
|
|
76
|
$text = HTML::Entities::encode_entities( $self->{text} ); |
207
|
|
|
|
|
|
|
} |
208
|
26
|
|
|
|
|
318
|
return $text; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head3 url |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
url(STRING) |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Overrides the self referencing URL for this heading. If the optional argument |
217
|
|
|
|
|
|
|
STRING is given the URL is set. Otherwise it is returned. The URL is used |
218
|
|
|
|
|
|
|
exactly as given. This means that any query params and values need to be |
219
|
|
|
|
|
|
|
added explicitely. If a URL is not set, the heading will get a default self |
220
|
|
|
|
|
|
|
referencing URL. For trivial applications, you will mostly be using this one. |
221
|
|
|
|
|
|
|
Note that generating the self referencing URL will be delayed until the tab |
222
|
|
|
|
|
|
|
widget it rendered. This means it will not be returned by the url() method. |
223
|
|
|
|
|
|
|
Example: |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
$h->url("www.someremotesite.com"); # go somewhere else |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
my $url = $h->url; # return the URL |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=cut |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub url { |
232
|
|
|
|
|
|
|
# |
233
|
|
|
|
|
|
|
# The redirect URL where this tab heading points to |
234
|
|
|
|
|
|
|
# |
235
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
236
|
0
|
0
|
|
|
|
|
if ( @_ ) { |
237
|
0
|
|
|
|
|
|
$self->{url} = shift; |
238
|
|
|
|
|
|
|
} |
239
|
0
|
|
|
|
|
|
return $self->{url}; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
1; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
__END__ |