blib/lib/CGI/Widget/Tabs.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 75 | 162 | 46.3 |
branch | 21 | 64 | 32.8 |
condition | 5 | 39 | 12.8 |
subroutine | 15 | 21 | 71.4 |
pod | 14 | 14 | 100.0 |
total | 130 | 300 | 43.3 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | =head1 MODULE FOR SALE | ||||||
2 | |||||||
3 | I am not planning to make any changes to this module as I have not had to use | ||||||
4 | it in any projects of my own for the last couple of years. I am aware that | ||||||
5 | others are using it. | ||||||
6 | |||||||
7 | If anyone would like to to take over maintenance/development of this module | ||||||
8 | pleas get in touch. | ||||||
9 | |||||||
10 | =head1 NAME | ||||||
11 | |||||||
12 | CGI::Widget::Tabs - Create tab widgets in HTML | ||||||
13 | |||||||
14 | =head1 SYNOPSIS | ||||||
15 | |||||||
16 | use CGI::Widget::Tabs; | ||||||
17 | my $tab = CGI::Widget::Tabs->new; | ||||||
18 | |||||||
19 | use CGI; | ||||||
20 | my $cgi = CGI->new; # interface to the query params | ||||||
21 | |||||||
22 | $tab->headings(@titles); # e.g. qw/Drivers Cars Courses/ | ||||||
23 | $tab->default("Courses"); # the default active tab | ||||||
24 | $tab->force_active("Courses"); # forceably make this the active tab | ||||||
25 | $tab->active; # the currently active tab | ||||||
26 | $tab->class("my_tab"); # the CSS class to use for markup | ||||||
27 | $tab->cgi_object($cgi); # the object holding the query params | ||||||
28 | $tab->cgi_param("t"); # the CGI query parameter to use | ||||||
29 | $tab->drop_params("ays"); # do NOT pass on "Are You Sure?" answers | ||||||
30 | $tab->wrap(4); # wrap after 4 headings... | ||||||
31 | $tab->indent(1); # ...and add indentation | ||||||
32 | $tab->render; # the resulting HTML code | ||||||
33 | $tab->display; # same as `print $tab->render' | ||||||
34 | |||||||
35 | |||||||
36 | $h = $tab->heading; # new OO heading for this tab | ||||||
37 | $h->text("TV Listings"); # heading text | ||||||
38 | $h->key("tv"); # key identifying this heading | ||||||
39 | $h->raw(1); # switch off HTML encoding | ||||||
40 | $h->url("whatsontonight.com"); # redirect URL for this heading | ||||||
41 | $h->class("red"); # this heading has it's own class | ||||||
42 | |||||||
43 | # See the EXAMPLE section for a complete example | ||||||
44 | |||||||
45 | =head1 DESCRIPTION | ||||||
46 | |||||||
47 | =head2 Introduction | ||||||
48 | |||||||
49 | CGI::Widget::Tabs lets you simulate tab widgets in HTML. You could benefit | ||||||
50 | from a tab widget if you want to serve only one page. Depending on the tab | ||||||
51 | selected you fetch and display the underlying data. There are three main | ||||||
52 | reasons for taking this approach: | ||||||
53 | |||||||
54 | 1. For the end user not to be directed to YAL or YAP (yet another link / yet | ||||||
55 | another page), but keep it all together: The single point of entry paradigm. | ||||||
56 | |||||||
57 | 2. As a consequence the end user deals with a more consistent and integrated | ||||||
58 | GUI. This will give a better "situational awareness" within the application. | ||||||
59 | |||||||
60 | 3. For the Perl hacker to handle multiple related data sources within the | ||||||
61 | same script environment. | ||||||
62 | |||||||
63 | |||||||
64 | As an example the following tabs could be used on a web page for someone's | ||||||
65 | spotting hobby: | ||||||
66 | |||||||
67 | __________ __________ __________ | ||||||
68 | / Planes \ / Trains \ / Classics \ | ||||||
69 | ------------------------------------------------------ | ||||||
70 | _________ | ||||||
71 | / Bikes \ | ||||||
72 | ------------------------ | ||||||
73 | |||||||
74 | As you can see, the headings wrap at three and a small indentation is added | ||||||
75 | to the start of the next row. The nice thing about CGI::Widget::Tabs is that | ||||||
76 | the tabs know their internal state. So you can ask a tab for instance which | ||||||
77 | heading has been clicked by the user. This way you get instant feedback. | ||||||
78 | |||||||
79 | =head2 "Hey Gorgeous!" | ||||||
80 | |||||||
81 | Of course tabs are useless if you can't "see" them. Without proper make up | ||||||
82 | they print as ordinary text. So you really need to fancy them up with some | ||||||
83 | eye candy. The designed way is that you provide a CSS style sheet and have | ||||||
84 | CGI::Widget::Tabs use that. See the class() method for how to do this. | ||||||
85 | |||||||
86 | |||||||
87 | =head1 EXAMPLE | ||||||
88 | |||||||
89 | Before digging into the API and all accessor methods, this example will | ||||||
90 | illustrate how to implement the spotting page from above. So you have | ||||||
91 | something to start with. It will give you enough clues to get on the road | ||||||
92 | quickly. The following code is a simple but complete example. Copy it and run | ||||||
93 | it through the webservers CGI engine. (For a even more complete and useful | ||||||
94 | demo with multiple tabs, see the file tabs-demo.pl in the CGI::Widget::Tabs | ||||||
95 | installation directory.) To fully appreciate it, it would be best to run it | ||||||
96 | in a performance environment, like mod_perl or SpeedyCGI. | ||||||
97 | |||||||
98 | #! /usr/bin/perl -w | ||||||
99 | |||||||
100 | use CGI::Widget::Tabs; | ||||||
101 | use CGI; | ||||||
102 | |||||||
103 | print < | ||||||
104 | Content-Type: text/html; | ||||||
105 | |||||||
106 | |||||||
107 | |||||||
114 | |||||||
115 | EOT | ||||||
116 | |||||||
117 | my $cgi = CGI->new; | ||||||
118 | my $tab = CGI::Widget::Tabs->new; | ||||||
119 | $tab->cgi_object($cgi); | ||||||
120 | $tab->headings( qw/Planes Traines Classics Bikes/ ); | ||||||
121 | $tab->wrap(3); | ||||||
122 | # $tab->wrap(1); # |uncomment to see the effect of | ||||||
123 | # $tab->indent(0); # |wrapping at 1 without indentation | ||||||
124 | $tab->default("Traines"); | ||||||
125 | $tab->display; | ||||||
126 | print " We now should run some intelligent code "; |
||||||
127 | print "to process ", $tab->active, " "; |
||||||
128 | print " |