Antispam-Toolkit

 view release on metacpan or  search on metacpan

lib/Antispam/Toolkit/Role/ContentChecker.pm  view on Meta::CPAN

package Antispam::Toolkit::Role::ContentChecker;
BEGIN {
  $Antispam::Toolkit::Role::ContentChecker::VERSION = '0.08';
}

use strict;
use warnings;
use namespace::autoclean;

use Antispam::Toolkit::Types qw( ArrayRef NonEmptyStr );
use List::AllUtils qw( first );

use Moose::Role;
use MooseX::Params::Validate qw( validated_hash );

requires qw( check_content _build_accepted_content_types );

has _accepted_content_types => (
    is       => 'bare',
    isa      => ArrayRef [NonEmptyStr],
    init_arg => undef,
    lazy     => 1,
    builder  => '_build_accepted_content_types',
);

around check_content => sub {
    my $orig = shift;
    my $self = shift;
    my %p    = validated_hash(
        \@_,
        content_type => { isa => NonEmptyStr },
        content      => { isa => NonEmptyStr },
    );

    return
        unless first { $_ eq $p{content_type} }
        @{ $self->_accepted_content_types() };

    return $self->$orig(@_);
};

1;

# ABSTRACT: A role for classes which check whether a piece of content is spam



=pod

=head1 NAME

Antispam::Toolkit::Role::ContentChecker - A role for classes which check whether a piece of content is spam

=head1 VERSION

version 0.08

=head1 SYNOPSIS

  package MyContentChecker;

  use Moose;

  with 'Antispam::Toolkit::Role::ContentChecker';

  sub check_content { ... }

=head1 DESCRIPTION

This role specifies an interface for classes which check whether a piece of
content is spam.

=head1 ATTRIBUTES

This role provides one attribute:

=head2 $checker->_accepted_content_types()

This is an array reference of non-empty strings. Each string should be a MIME
type. This attribute cannot be set by the constructor. The class consuming the
role must provide a C<< $checker->_build_accepted_content_types() >> method.

=head1 REQUIRED METHODS

Classes which consume this method must provide two methods:

=head2 $checker->_build_accepted_content_types()

This method should return an array reference of mime types which the class can



( run in 0.580 second using v1.01-cache-2.11-cpan-39bf76dae61 )