line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#$Id: Validator.pm,v 1.1 2005/11/14 03:39:09 naoya Exp $ |
2
|
|
|
|
|
|
|
package Acme::Web20::Validator; |
3
|
2
|
|
|
2
|
|
57923
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
82
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
135
|
|
5
|
2
|
|
|
2
|
|
11
|
use base qw(Class::Accessor); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
1833
|
|
6
|
2
|
|
|
2
|
|
5008
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
182
|
|
7
|
2
|
|
|
2
|
|
2518
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
111038
|
|
|
2
|
|
|
|
|
82
|
|
8
|
2
|
|
|
2
|
|
26485
|
use Text::ASCIITable; |
|
2
|
|
|
|
|
57866
|
|
|
2
|
|
|
|
|
128
|
|
9
|
2
|
|
|
2
|
|
1618
|
use Acme::Web20::Validator::Rule; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
31
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.01; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(ua is_validated ok_count)); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
2
|
|
|
2
|
1
|
21
|
my $class = shift; |
17
|
2
|
|
|
|
|
8
|
my $self = bless {}, $class; |
18
|
2
|
|
|
|
|
8
|
$self->_init(@_); |
19
|
2
|
|
|
|
|
21
|
$self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _init { |
23
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
24
|
2
|
|
|
|
|
16
|
$self->{_rules} = []; |
25
|
2
|
|
|
|
|
25
|
$self->ua(LWP::UserAgent->new); |
26
|
2
|
|
|
|
|
93963
|
$self->ua->agent(__PACKAGE__ . "/" . $VERSION); |
27
|
2
|
|
|
|
|
164
|
$self->ok_count(0); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub add_rule { |
31
|
2
|
|
|
2
|
1
|
14275
|
my $self = shift; |
32
|
2
|
|
|
|
|
7
|
push @{$self->{_rules}}, @_; |
|
2
|
|
|
|
|
15
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub clear { |
36
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
37
|
0
|
|
|
|
|
0
|
$self->ok_count(0); |
38
|
0
|
|
|
|
|
0
|
$self->is_validated(0); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub set_all_rules { |
42
|
1
|
|
|
1
|
1
|
10
|
shift->add_rule(Acme::Web20::Validator::Rule->new->plugins); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub rules_size { |
46
|
4
|
|
|
4
|
1
|
4464
|
my $self = shift; |
47
|
4
|
|
|
|
|
8
|
return scalar @{$self->{_rules}}; |
|
4
|
|
|
|
|
29
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub validate { |
51
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
52
|
1
|
50
|
|
|
|
5
|
$self->is_validated and return @{$self->{_rules}}; |
|
0
|
|
|
|
|
0
|
|
53
|
1
|
|
|
|
|
16
|
my $response = $self->_get_remote(@_); |
54
|
1
|
|
|
|
|
3
|
for my $rule (@{$self->{_rules}}) { |
|
1
|
|
|
|
|
6
|
|
55
|
11
|
50
|
|
|
|
197
|
unless (ref $rule) { |
56
|
11
|
|
|
1
|
|
813
|
eval "use $rule"; |
|
1
|
|
|
1
|
|
775
|
|
|
1
|
|
|
1
|
|
5
|
|
|
1
|
|
|
1
|
|
15
|
|
|
1
|
|
|
1
|
|
660
|
|
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
1
|
|
12
|
|
|
1
|
|
|
1
|
|
1551
|
|
|
1
|
|
|
1
|
|
3
|
|
|
1
|
|
|
1
|
|
13
|
|
|
1
|
|
|
1
|
|
657
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
663
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
640
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
590
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
805
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
764
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
689
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
564
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
57
|
11
|
50
|
|
|
|
193
|
if ($@) { |
58
|
0
|
|
|
|
|
0
|
warn $@; |
59
|
0
|
|
|
|
|
0
|
next; |
60
|
|
|
|
|
|
|
} |
61
|
11
|
|
|
|
|
109
|
$rule = $rule->new |
62
|
|
|
|
|
|
|
} |
63
|
11
|
|
|
|
|
197
|
$rule->validate($response); |
64
|
11
|
100
|
|
|
|
4593
|
$self->ok_count($self->ok_count + 1) if $rule->is_ok; |
65
|
|
|
|
|
|
|
} |
66
|
1
|
|
|
|
|
16
|
$self->is_validated(1); |
67
|
1
|
|
|
|
|
20
|
return @{$self->{_rules}}; |
|
1
|
|
|
|
|
52
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub validation_report { |
71
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
72
|
1
|
50
|
|
|
|
5
|
my @rules = $self->is_validated ? @{$self->{_rules}} : $self->validate(@_); |
|
1
|
|
|
|
|
20
|
|
73
|
1
|
|
|
|
|
12
|
my $t = Text::ASCIITable->new; |
74
|
1
|
|
|
|
|
56
|
$t->setCols('Rule', 'Result'); |
75
|
1
|
100
|
|
|
|
143
|
$t->addRow($_->name, $_->is_ok ? 'Yes!' : 'No') for @rules; |
76
|
1
|
|
|
|
|
1646
|
return $t->draw; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _get_remote { |
80
|
1
|
|
|
1
|
|
1
|
my $self = shift; |
81
|
1
|
50
|
|
|
|
4
|
my $url = shift or croak 'usage: $validator->validate($url)'; |
82
|
1
|
|
|
|
|
4
|
my $response = $self->ua->get($url); |
83
|
1
|
50
|
|
|
|
254786
|
croak "Could'nt get $url " . $response->status_line |
84
|
|
|
|
|
|
|
unless $response->is_success; |
85
|
1
|
|
|
|
|
22
|
return $response; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |