File Coverage

blib/lib/HTML/Widget/JavaScript.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package HTML::Widget::JavaScript;
2            
3 1     1   30121 use warnings;
  1         3  
  1         31  
4 1     1   6 use strict;
  1         2  
  1         33  
5            
6 1     1   5 use base 'HTML::Widget';
  1         6  
  1         573  
7            
8 1     1   570 use HTML::Widget::JavaScript::Result;
  0            
  0            
9            
10             =head1 NAME
11            
12             HTML::Widget::JavaScript - Adds JavaScript validation to HTML::Widget
13            
14             =head1 VERSION
15            
16             Version 0.02
17            
18             =cut
19            
20             our $VERSION = '0.02';
21            
22             =head1 UNMAINTAINED MODULE
23            
24             B
25            
26             B
27            
28             =head1 SYNOPSIS
29            
30             This module adds JavaScript field validation for L objects.
31            
32             When a JavaScript checked constraint fails, an alert box with the given error
33             message (set by the C constraint method) is displayed.
34            
35             Currently, these constraints are implemented in JavaScript: All, AllOrNone, Any,
36             ASCII, Email (simplified), Equal, HTTP, In, Integer, Length, Printable, Range
37             and String.
38            
39             In other words, these constraints are missing: Date, DateTime, Time and Regex.
40             Note that, although JavaScript support is missing, they will continue to work
41             using server-side validation.
42            
43             =head1 METHODS
44            
45             See L.
46            
47             =cut
48            
49             *result = \&process;
50            
51             =head2 $self->result( $query, $uploads )
52            
53             =head2 $self->process( $query, $uploads )
54            
55             After finishing setting up the widget and all its elements, call either
56             C or C to create an L.
57             If passed a C<$query> it will run filters and validation on the parameters.
58             The Result object can then be used to produce the HTML.
59            
60             =cut
61            
62             sub process {
63             my ( $self, $query, $uploads ) = @_;
64             bless $self->SUPER::process($query, $uploads), 'HTML::Widget::JavaScript::Result';
65             }
66            
67             sub _instantiate {
68             my ( $self, $class, @args ) = @_;
69            
70             (my $js_class = $class) =~ s/HTML::Widget/HTML::Widget::JavaScript/;
71             eval "require $js_class";
72             if ($@) {
73             return $self->SUPER::_instantiate($class, @args);
74             }
75            
76             return $js_class->new(@args);
77             }
78            
79             =head1 TODO
80            
81             Implement the missing constraints.
82            
83             Maybe add support for altering the error displaying behaviour (e.g. instead of
84             using alert(), maybe we could fill the error span with the error messages
85             directly through JavaScript).
86            
87             =head1 AUTHOR
88            
89             Nilson Santos Figueiredo Júnior, C<< >>
90            
91             =head1 BUGS
92            
93             Please report any bugs or feature requests directly to the author.
94             If you ask nicely it will probably get fixed or implemented.
95            
96             =head1 SUPPORT
97            
98             You can find documentation for this module with the perldoc command.
99            
100             perldoc HTML::Widget::JavaScript
101            
102             You can also look for information at:
103            
104             =over 4
105            
106             =item * AnnoCPAN: Annotated CPAN documentation
107            
108             L
109            
110             =item * CPAN Ratings
111            
112             L
113            
114             =item * Search CPAN
115            
116             L
117            
118             =back
119            
120             =head1 SEE ALSO
121            
122             L
123            
124             =head1 COPYRIGHT & LICENSE
125            
126             Copyright 2006, 2009 Nilson Santos Figueiredo Júnior, all rights reserved.
127            
128             This program is free software; you can redistribute it and/or modify it
129             under the same terms as Perl itself.
130            
131             =cut
132            
133             1; # End of HTML::Widget::JavaScript