File Coverage

blib/lib/Data/Validate/WithYAML/Plugin/NoSpam.pm
Criterion Covered Total %
statement 15 15 100.0
branch 6 6 100.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 26 26 100.0


line stmt bran cond sub pod time code
1             package Data::Validate::WithYAML::Plugin::NoSpam;
2              
3 3     3   1252120 use warnings;
  3         23  
  3         102  
4 3     3   17 use strict;
  3         6  
  3         61  
5              
6 3     3   15 use Carp;
  3         7  
  3         743  
7              
8             # ABSTRACT: Plugin to check that a given text is no spam.
9              
10             our $VERSION = '0.03';
11              
12              
13             sub check {
14 5     5 1 1532 my ($class, $value) = @_;
15            
16 5 100       221 croak "no value to check" unless defined $value;
17            
18 4 100       38 if ( $value =~ /(?:\[url|<a href)/ ) {
    100          
19 2         7 return 0;
20             }
21             elsif ( $value =~ /viagra|cialis/i ) {
22 1         4 return 0;
23             }
24            
25 1         7 return 1;
26             }
27              
28              
29             1; # End of Data::Validate::WithYAML::Plugin::NoSpam
30              
31             __END__
32              
33             =pod
34              
35             =encoding UTF-8
36              
37             =head1 NAME
38              
39             Data::Validate::WithYAML::Plugin::NoSpam - Plugin to check that a given text is no spam.
40              
41             =head1 VERSION
42              
43             version 0.03
44              
45             =head1 SYNOPSIS
46              
47             The check is done with heuristics. It checks that there are no
48             <a href="..."> or [url=""] tags in the text...
49              
50             use Data::Validate::WithYAML::Plugin::NoSpam;
51              
52             my $foo = Data::Validate::WithYAML::Plugin::NoSpam->check(
53             'This is a <a href="anything">Spam-Link</a>',
54             );
55             ...
56            
57             # use the plugin via Data::Validate::WithYAML
58            
59             use Data::Validate::WithYAML;
60            
61             my $text = 'This is a <a href="anything">Spam-Link</a>';
62             my $validator = Data::Validate::WithYAML->new( 'test.yml' );
63             print "yes" if $validator->check( 'textfield', $text );
64              
65             test.yml
66              
67             ---
68             step1:
69             textfield:
70             plugin: NoSpam
71             type: required
72              
73             =head1 SUBROUTINES
74              
75             =head2 check
76              
77             =head1 AUTHOR
78              
79             Renee Baecker, C<< <module at renee-baecker.de> >>
80              
81             =head1 BUGS
82              
83             Please report any bugs or feature requests to
84             C<bug-data-validate-withyaml-plugin-NoSpam at rt.cpan.org>, or through the web interface at
85             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-Validate-WithYAML-Plugin-NoSpam>.
86             I will be notified, and then you'll automatically be notified of progress on
87             your bug as I make changes.
88              
89             =head1 SUPPORT
90              
91             You can find documentation for this module with the perldoc command.
92              
93             perldoc Data::Validate::WithYAML::Plugin::NoSpam
94              
95             You can also look for information at:
96              
97             =over 4
98              
99             =item * AnnoCPAN: Annotated CPAN documentation
100              
101             L<http://annocpan.org/dist/Data::Validate::WithYAML::Plugin::NoSpam>
102              
103             =item * CPAN Ratings
104              
105             L<http://cpanratings.perl.org/d/Data::Validate::WithYAML::Plugin::NoSpam>
106              
107             =item * RT: CPAN's request tracker
108              
109             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data::Validate::WithYAML::Plugin::NoSpam>
110              
111             =item * Search CPAN
112              
113             L<http://search.cpan.org/dist/Data::Validate::WithYAML::Plugin::NoSpam>
114              
115             =back
116              
117             =head1 ACKNOWLEDGEMENTS
118              
119             =head1 COPYRIGHT & LICENSE
120              
121             Copyright 2007 Renee Baecker, all rights reserved.
122              
123             This program is free software; you can redistribute it and/or modify it
124             under the same terms as Perl itself.
125              
126             =head1 AUTHOR
127              
128             Renee Baecker <module@renee-baecker.de>
129              
130             =head1 COPYRIGHT AND LICENSE
131              
132             This software is Copyright (c) 2012 by Renee Baecker.
133              
134             This is free software, licensed under:
135              
136             The Artistic License 2.0 (GPL Compatible)
137              
138             =cut