App-ZofCMS-PluginBundle-Naughty
view release on metacpan or search on metacpan
lib/App/ZofCMS/Plugin/Captcha.pm view on Meta::CPAN
package App::ZofCMS::Plugin::Captcha;
use warnings;
use strict;
our $VERSION = '1.001002'; # VERSION
use base 'App::ZofCMS::Plugin::Base';
use GD::SecurityImage;
sub _key { 'plug_captcha' }
sub _defaults {
string => undef,
file => undef,
width => 80,
height => 20,
lines => 5,
particle => 0,
no_exit => 1,
style => 'rect',
format => 'gif',
tcolor => '#895533',
lcolor => '#000000',
}
sub _do {
my ( $self, $conf, $t, $q, $config ) = @_;
my $image = GD::SecurityImage->new(
width => $conf->{width},
height => $conf->{height},
lines => $conf->{lines},
gd_font => 'giant'
);
$image->random( $conf->{string} );
$image->create('normal', @$conf{qw/style tcolor lcolor/} );
if ( $conf->{particle} ) {
$image->particle( ref $conf->{particle} ? @{ $conf->{particle} } : () );
}
my ( $image_data, $mime_type, $random_number ) = $image->out( force => $conf->{format} );
$t->{d}{session}{captcha} = $random_number;
if ( defined $conf->{file} and length $conf->{file} ) {
if ( open my $fh, '>', $conf->{file} ) {
binmode $fh;
print $fh $image_data;
close $fh;
}
else {
$t->{t}{plug_captcha_error} = $!;
return;
}
}
else {
binmode STDOUT;
print "Content-Type: image/$mime_type\n\n";
print $image_data;
exit
unless $conf->{no_exit};
}
}
1;
__END__
=encoding utf8
=for stopwords RGB bots captcha captchas crypto cryptocrap runcycle runlevel subref
=head1 NAME
App::ZofCMS::Plugin::Captcha - plugin to utilize security images (captchas)
=head1 SYNOPSIS
plugins => [
{ Session => 1000 },
{ Captcha => 2000 },
],
plugins2 => [
qw/Session/
],
plug_captcha => {},
# Session plugin configuration (i.e. database connection is left out for brevity)
=head1 DESCRIPTION
The module is a plugin for L<App::ZofCMS> that provides means to generate and display
( run in 2.018 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )