line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Spry::DataSet; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
HTML::Spry::DataSet - Generate HTML Table Data Set files for the Spry Javascript toolkit |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Create the object |
12
|
|
|
|
|
|
|
my $dataset = HTML::Spry::DataSet->new; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Add the tables to the object |
15
|
|
|
|
|
|
|
$dataset->add( 'heavy100', |
16
|
|
|
|
|
|
|
[ 'Rank', 'Dependencies', 'Author', 'Distribution' ], |
17
|
|
|
|
|
|
|
[ '1', '748', 'APOCAL', 'Task-POE-All' ], |
18
|
|
|
|
|
|
|
[ '2', '276', 'MRAMBERG', 'MojoMojo-Formatter-RSS' ], |
19
|
|
|
|
|
|
|
... |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Write out to the HTML file |
23
|
|
|
|
|
|
|
$dataset->write('dataset.html'); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Spry is a JavaScript framework produced by Adobe. The following is taken |
28
|
|
|
|
|
|
|
from their website. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
I<"The Spry framework for Ajax is a JavaScript library that provides |
31
|
|
|
|
|
|
|
easy-to-use yet powerful Ajax functionality that allows designers |
32
|
|
|
|
|
|
|
to build pages that provide a richer experience for their users.> |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
I
|
35
|
|
|
|
|
|
|
to easily create Web 2.0 pages."> |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
This package is used to generate simple HTML-formatted data sets that are |
38
|
|
|
|
|
|
|
consumable by Spry DataSet objects, for use in generating various dynamic |
39
|
|
|
|
|
|
|
JavaScript-driven page elements, such as dynamic tables, reports and so on. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
The SYNOPSIS section covers pretty much everything you need to know about |
42
|
|
|
|
|
|
|
using B. All methods throw an exception on error. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
|
2
|
|
990634
|
use 5.008005; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
87
|
|
47
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
66
|
|
48
|
2
|
|
|
2
|
|
23
|
use Carp (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
31
|
|
49
|
2
|
|
|
2
|
|
4151
|
use CGI (); |
|
2
|
|
|
|
|
41584
|
|
|
2
|
|
|
|
|
60
|
|
50
|
2
|
|
|
2
|
|
1995
|
use IO::File (); |
|
2
|
|
|
|
|
24669
|
|
|
2
|
|
|
|
|
69
|
|
51
|
2
|
|
|
2
|
|
2528
|
use Params::Util qw{ _IDENTIFIER _ARRAY _STRING }; |
|
2
|
|
|
|
|
7153
|
|
|
2
|
|
|
|
|
1285
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new { |
56
|
1
|
|
|
1
|
0
|
92
|
my $class = shift; |
57
|
1
|
|
|
|
|
4
|
my $self = bless { }, $class; |
58
|
1
|
|
|
|
|
3
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub add { |
62
|
2
|
|
|
2
|
0
|
978
|
my $self = shift; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Check the dataset name |
65
|
2
|
|
|
|
|
4
|
my $name = shift; |
66
|
2
|
50
|
|
|
|
97
|
unless ( _IDENTIFIER($name) ) { |
67
|
0
|
|
|
|
|
0
|
Carp::croak("Missing or invalid dataset identifier"); |
68
|
|
|
|
|
|
|
} |
69
|
2
|
50
|
|
|
|
27
|
if ( $self->{$name} ) { |
70
|
0
|
|
|
|
|
0
|
Carp::croak("The dataset '$name' already exists"); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Check the records |
74
|
2
|
|
|
|
|
4
|
my $rowid = 0; |
75
|
2
|
|
|
|
|
4
|
foreach my $row ( @_ ) { |
76
|
6
|
50
|
|
|
|
22
|
unless ( _ARRAY($row) ) { |
77
|
0
|
|
|
|
|
0
|
Carp::croak("Row $rowid in dataset $name is not an ARRAY reference"); |
78
|
|
|
|
|
|
|
} |
79
|
6
|
50
|
|
|
|
10
|
if ( scalar grep { not defined _STRING($_) } @$row ) { |
|
24
|
|
|
|
|
59
|
|
80
|
0
|
|
|
|
|
0
|
Carp::croak("Row $rowid in dataset $name contained a non-SCALAR column"); |
81
|
|
|
|
|
|
|
} |
82
|
6
|
|
|
|
|
10
|
$rowid++; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Add the dataset |
86
|
2
|
|
|
|
|
7
|
$self->{$name} = [ @_ ]; |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
5
|
return 1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub write { |
92
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Open the file |
95
|
1
|
|
|
|
|
3
|
my $file = shift; |
96
|
1
|
|
|
|
|
11
|
my $html = IO::File->new( $file, "w" ); |
97
|
1
|
50
|
|
|
|
238
|
unless ( defined $html ) { |
98
|
0
|
|
|
|
|
0
|
Carp::croak("Failed to open '$file' for write"); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Write the file |
102
|
1
|
|
|
|
|
11
|
$html->say(''); |
103
|
1
|
|
|
|
|
33
|
$html->say(''); |
104
|
1
|
|
|
|
|
10
|
$html->say(''); |
105
|
1
|
|
|
|
|
10
|
$html->say(''); |
106
|
1
|
|
|
|
|
9
|
$html->say(''); |
107
|
1
|
|
|
|
|
9
|
$html->say(''); |
108
|
1
|
|
|
|
|
13
|
foreach my $id ( sort keys %$self ) { |
109
|
2
|
|
|
|
|
16
|
$html->say("");
110
|
2
|
|
|
|
|
15
|
foreach my $row ( @{ $self->{$id} } ) { |
|
2
|
|
|
|
|
6
|
|
111
|
6
|
|
|
|
|
41
|
$html->say(' | ');
112
|
6
|
|
|
|
|
41
|
foreach my $cell ( @$row ) { |
113
|
24
|
|
|
|
|
697
|
my $text = CGI::escapeHTML($cell); |
114
|
24
|
|
|
|
|
6452
|
$html->say(" | $text | ");
115
|
|
|
|
|
|
|
} |
116
|
6
|
|
|
|
|
62
|
$html->say(' | ');
117
|
|
|
|
|
|
|
} |
118
|
2
|
|
|
|
|
20
|
$html->say(' | '); |
119
|
|
|
|
|
|
|
} |
120
|
1
|
|
|
|
|
15
|
$html->say(''); |
121
|
1
|
|
|
|
|
9
|
$html->say(''); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Clean up |
124
|
1
|
|
|
|
|
17
|
$html->close; |
125
|
|
|
|
|
|
|
|
126
|
1
|
|
|
|
|
152
|
return 1; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=pod |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SUPPORT |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Bugs should be reported via the CPAN bug tracker at |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
For other issues, or commercial enhancement or support, contact the author. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 AUTHORS |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Adam Kennedy Eadamk@cpan.orgE |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 COPYRIGHT |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Copyright 2009 Adam Kennedy. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This program is free software; you can redistribute |
150
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
The full text of the license can be found in the |
153
|
|
|
|
|
|
|
LICENSE file included with this module. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |