Plugin/Captcha.pm

filter: Statementstmt 100% 12 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 16 / 16 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Plugin/ImageGallery.pm ↑ Summary PluginBundle/Naughty.pm »
1 package App::ZofCMS::Plugin::Captcha;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 our $VERSION = '1.001003'; # VERSION
7  
8 3 ▶use base 'App::ZofCMS::Plugin::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use GD::SecurityImage;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub _key { 'plug_captcha' }
12 sub _defaults {
13 string => undef,
14 file => undef,
15 width => 80,
16 height => 20,
17 lines => 5,
18 particle => 0,
19 no_exit => 1,
20 style => 'rect',
21 format => 'gif',
22 tcolor => '#895533',
23 lcolor => '#000000',
24 }
25 sub _do {
26 my ( $self, $conf, $t, $q, $config ) = @_;
27  
28 my $image = GD::SecurityImage->new(
29 width => $conf->{width},
30 height => $conf->{height},
31 lines => $conf->{lines},
32 gd_font => 'giant'
33 );
34  
35 $image->random( $conf->{string} );
36 $image->create('normal', @$conf{qw/style tcolor lcolor/} );
37  
38 if ( $conf->{particle} ) {
39 $image->particle( ref $conf->{particle} ? @{ $conf->{particle} } : () );
40 }
41  
42 my ( $image_data, $mime_type, $random_number ) = $image->out( force => $conf->{format} );
43 $t->{d}{session}{captcha} = $random_number;
44  
45 if ( defined $conf->{file} and length $conf->{file} ) {
46 if ( open my $fh, '>', $conf->{file} ) {
47 binmode $fh;
48 print $fh $image_data;
49 close $fh;
50 }
51 else {
52 $t->{t}{plug_captcha_error} = $!;
53 return;
54 }
55 }
56 else {
57 binmode STDOUT;
58 print "Content-Type: image/$mime_type\n\n";
59 print $image_data;
60 exit
61 unless $conf->{no_exit};
62 }
63 }
64  
65 1;
66 __END__
« Plugin/ImageGallery.pm ↑ Summary PluginBundle/Naughty.pm »