Toolkit/Role/ContentChecker.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 45 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Antispam::Toolkit::Role::ContentChecker;
2 BEGIN {
3 $Antispam::Toolkit::Role::ContentChecker::VERSION = '0.08';
4 }
5  
6 use strict;
7 use warnings;
8 use namespace::autoclean;
9  
10 use Antispam::Toolkit::Types qw( ArrayRef NonEmptyStr );
11 use List::AllUtils qw( first );
12  
13 use Moose::Role;
14 use MooseX::Params::Validate qw( validated_hash );
15  
16 requires qw( check_content _build_accepted_content_types );
17  
18 has _accepted_content_types => (
19 is => 'bare',
20 isa => ArrayRef [NonEmptyStr],
21 init_arg => undef,
22 lazy => 1,
23 builder => '_build_accepted_content_types',
24 );
25  
26 around check_content => sub {
27 my $orig = shift;
28 my $self = shift;
29 my %p = validated_hash(
30 \@_,
31 content_type => { isa => NonEmptyStr },
32 content => { isa => NonEmptyStr },
33 );
34  
35 return
36 unless first { $_ eq $p{content_type} }
37 @{ $self->_accepted_content_types() };
38  
39 return $self->$orig(@_);
40 };
41  
42 1;
43  
44 # ABSTRACT: A role for classes which check whether a piece of content is spam
45  
46  
47  
48 =pod
49  
50 =head1 NAME
51  
52 Antispam::Toolkit::Role::ContentChecker - A role for classes which check whether a piece of content is spam
53  
54 =head1 VERSION
55  
56 version 0.08
57  
58 =head1 SYNOPSIS
59  
60 package MyContentChecker;
61  
62 use Moose;
63  
64 with 'Antispam::Toolkit::Role::ContentChecker';
65  
66 sub check_content { ... }
67  
68 =head1 DESCRIPTION
69  
70 This role specifies an interface for classes which check whether a piece of
71 content is spam.
72  
73 =head1 ATTRIBUTES
74  
75 This role provides one attribute:
76  
77 =head2 $checker->_accepted_content_types()
78  
79 This is an array reference of non-empty strings. Each string should be a MIME
80 type. This attribute cannot be set by the constructor. The class consuming the
81 role must provide a C<< $checker->_build_accepted_content_types() >> method.
82  
83 =head1 REQUIRED METHODS
84  
85 Classes which consume this method must provide two methods:
86  
87 =head2 $checker->_build_accepted_content_types()
88  
89 This method should return an array reference of mime types which the class can
90 check, such as "text/html", "text/plain", etc.
91  
92 =head2 $checker->check_content( ... )
93  
94 This method implements the actual spam checking for a piece of content. It
95 must accept the following named parameters:
96  
97 =over 4
98  
99 =item * content_type
100  
101 The MIME type for the piece of content.
102  
103 =item * content
104  
105 The content itself. This must be a non-empty string.
106  
107 =back
108  
109 =head1 METHODS
110  
111 This role provides an around modifier for the C<< $checker->check_content() >>
112 method. The modifier does validation on all the parameters, so there's no need
113 to implement this in the class itself.
114  
115 If the provided C<content_type> is not one of the accepted types, the original
116 method will not be called.
117  
118 =head1 BUGS
119  
120 See L<Antispam::Toolkit> for bug reporting details.
121  
122 =head1 AUTHOR
123  
124 Dave Rolsky <autarch@urth.org>
125  
126 =head1 COPYRIGHT AND LICENSE
127  
128 This software is Copyright (c) 2011 by Dave Rolsky.
129  
130 This is free software, licensed under:
131  
132 The Artistic License 2.0 (GPL Compatible)
133  
134 =cut
135  
136  
137 __END__