File: Extratags.pm

package info (click to toggle)
cgi-extratags-perl 0.02-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 36 kB
  • ctags: 12
  • sloc: perl: 51; makefile: 42
file content (232 lines) | stat: -rw-r--r-- 4,727 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# Extratags.pm - Useful Extensions for the CGI Module

# Copyright (C) 1999 Stefan Hornburg

# Author: Stefan Hornburg <racke@linuxia.net>
# Maintainer: Stefan Hornburg <racke@linuxia.net>
# Version: 0.02

# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.

# This file is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this file; see the file COPYING.  If not, write to the Free
# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

package CGI::Extratags;

use strict;
use vars qw($VERSION @ISA $AutoloadClass);
$VERSION = '0.02';

use URI::Escape;
use CGI;
$CGI::DefaultClass = __PACKAGE__;
$AutoloadClass = 'CGI';

@ISA = qw(CGI);

=head1 NAME

CGI::Extratags - Useful Extensions for the CGI Module

=head1 SYNOPSIS

  use CGI::Extratags;
  $cgi = new CGI::Extratags;

  print $cgi -> email ('racke@linuxia.net');

  print $cgi -> jump ('CONTACT', 'contact us');
  print $cgi -> mark ('CONTACT', $cgi -> h2 ('How to contact us'));

  print $cgi -> row ('Date', 18, 1, 1966);
  print $cgi -> recall ('Debian CD', artnum => '0-123456');

=head1 DESCRIPTION

CGI::Extratags adds several useful methods to the CGI class.

=cut

# Variables
# =========

my $maintainer_adr = 'racke@linuxia.net';

sub new ($$)
  {
	my $proto = shift;
	my $class = ref ($proto) || $proto;
	my $self = $class -> SUPER::new (@_);


	bless ($self, $class);
	return ($self);
  }

# --------------------------------------------------
# METHOD: email ADDRESS
#
# Produces HTML code for a link to an email ADDRESS.
# --------------------------------------------------

=over 4

=item email I<ADDRESS>

  print $cgi -> email ('racke@linuxia.net');

Produces HTML code for a link to an email I<ADDRESS>.

=back

=cut

sub email
  {
	my ($cgi, $address) = @_;

	$cgi -> a ({href=>"mailto:$address"}, "&lt;$address&gt;");
  }

# --------------------------------------------------
# METHOD: jump MARK TEXT
#
# Produces HTML code for a link pointing to a target
# within the current document.
# --------------------------------------------------

=over 4

=item jump I<MARK> I<TEXT>

  print $cgi -> jump ('CONTACT', 'contact us');

Produces HTML code for a link pointing to a target
within the current document.

=back

=cut

sub jump
  {
	my ($cgi, $mark, $text) = @_;

	$cgi -> a ({href => "#$mark"}, $text);
  }

# ----------------------
# METHOD: mark NAME TEXT
#
# Generates link target.
# ----------------------

=over 4

=item mark I<NAME> I<TEXT>

  print $cgi -> mark ('CONTACT', $cgi -> h2 ('How to contact us'));

Generates target I<NAME> for hyperlinks.

=back

=cut

sub mark
  {
	my ($cgi, $name, $text) = @_;

	$cgi -> a ({name => $name}, $text);
  }

# -------------------------------------------------------
# METHOD: row [ITEM ...]
#
# Creates table row with ITEM arguments as cell contents.
# -------------------------------------------------------

=over 4

=item row [I<ITEM> ...]

  print $cgi -> row ('Date', 18, 1, 1966);

Produces HTML code for a table row with I<ITEM> arguments as cell
contents.

=back

=cut

sub row
  {
	my $cgi = shift;
	
	$cgi -> Tr (map {ref($_) eq 'HASH' ? $_ : $cgi -> td ($_)} @_);
  }

# -----------------------------------------------------------------
# METHOD: recall TEXT [NAME [VALUE]] ...
#
# Produces a link to the script itself with the NAME/VALUE pairs as
# parameter list labeled with TEXT.
# -----------------------------------------------------------------

=over 4

=item recall I<TEXT> [I<NAME> [I<VALUE>]] ...

  foreach my $num (sort (keys %artmap))
    {
	print $cgi -> recall ($artmap{$num}, artnum => $num);
	print $cgi -> br;
    }

Produces a link to the script itself labeled with I<TEXT>. The
I<NAME>/I<VALUE> pairs will be passed as parameters.

=back

=cut

sub recall
  {
	my $cgi = shift; my $text = shift;
	my $query = ''; my @params; my $link;
	
	# generate query string
	while ($#_ >= 0)
	  {
		push (@params, uri_escape (shift) . '=' . uri_escape (shift));
	  }
	$query = '?' . join ('&', @params) if ($#params >= 0);

	# generate link
	$link = $cgi -> url (-relative => 1) || '';
	$cgi -> a ({href => $link . $query}, $text);
  }
		
1;
__END__

# Autoload methods go here, and are processed by the autosplit program.

=head1 AUTHOR

Stefan Hornburg, racke@linuxia.net

=head1 SEE ALSO

perl(1), URI::Escape(3), CGI(3).

=cut