blib/lib/CGI/Application/Plugin/Email.pm

filter: Statementstmt 78.7% 37 / 47 Branchbran 25.0% 2 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod n/a totaltotal 70.7% 46 / 65 CC 5 SCAR 10.4
CC
5
Cov
71%
import
5.3
__ANON__
4.3
new
2.0
CRAP 2.8
↑ Summary
1 package CGI::Application::Plugin::Email;
2
3
4 =head1 NAME
5
6 CGI::Application::Plugin::Email - Lazy loaded Email
7
8 =head1 SYNOPSIS
9
10 Just a little wrapper around Email::Stuff. Useful to add easy emailing
11 functionality without loading having to load the library unless it's actually
12 called.
13
14 use CGI::Application::Plugin::Email qw( :std );
15
16 Creating a new Email::Stuff object:-
17
18 $email = $self->Email->new;
19
20 If you aren't happy with importing a method named C<Email> into your namespace
21 then you can choose the method name:-
22
23 use CGI::Application::Plugin::Email ( ':std', { method => 'EmailStuff' } );
24
25 Creating a new Email::Stuff object:-
26
27 $email = $self->EmailStuff->new;
28
29
30 =head1 DESCRIPTION
31
32 This module is a wrapper around C<Email::Stuff>.
33 The only real benefit is the lazy loading so that Email::Stuff isn't loaded with
34 every request. This makes it a good option for scripts running through CGI.
35
36 =head1 Methods
37
38 =head2 Email
39
40 This is the object that gets exported.
41 See L</SYNOPSIS>
42
43 =head1 Export groups
44
45 Only an Email:::Stuff object can be exported. It's not exported by default,
46 but this module is pretty useless without it. You can choose the name of the
47 method that invokes the object.
48
49 :std exports:-
50
51 Email
52
53 =head1 FAQ
54
55 =head2 How do I send email?
56
57 View the L<Email::Stuff> documentation on how to use the returned email object
58 to send mail.
59
60 =head2 Why?
61
62 Emailing can be a pain, wanted a quick and easy way of doing it. Email::Stuff
63 provides that, but I didn't want it slowing down my cgi requests that didn't
64 actually use it. Also there were no CGI::Application plugins for sending email,
65 so a plugin providing an easy path to emailing for new people seemed a good
66 idea :)
67
68 =head1 Thanks to:-
69
70 L<Email::Stuff>
71
72 Adam Kennedy for creating Email::Stuff and for making sure it had Pure Perl
73 dependency options when I asked him :)
74
75 =head1 Come join the bestest Perl group in the World!
76
77 Bristol and Bath Perl moungers is renowned for being the friendliest Perl group
78 in the world. You don't have to be from the UK to join, everyone is welcome on
79 the list:-
80 L<http://perl.bristolbath.org>
81
82 =head1 AUTHOR
83
84 Lyle Hopkins ;)
85
86 =cut
87
88
89
90 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
93
94 2 ▶use vars qw ( $VERSION @ISA @EXPORT_OK %EXPORT_TAGS );
Subroutine BEGIN: called CC=1 SCAR=0.0
95
96 2 require Exporter;
97 2 @ISA = qw(Exporter);
98
99 2 @EXPORT_OK = ();
100
101 2 %EXPORT_TAGS = (
102 std => [],
103 );
104
105 2 $VERSION = '0.01';
106
107 2 my $email;
108
109 1 ▶sub import {
Subroutine import: called CC=4 SCAR=16.6
110 1 $email = new__ CGI::Application::Plugin::Email::guts;
111 1 my $exportmethod = 'Email';
112 1 ▶ if ( ref $_[ $#_ ] eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[$#_] eq "HASH") 0 1 1
113 0 my $attrib = pop @_;
114 0 ▶ $exportmethod = $attrib->{method} if ( $attrib->{method} );
Branch: 1 branch
BranchTrueFalseTotal
if $attrib->{"method"} 0 0 0
115 }#if
116 ### Check name if legal
117 1 ▶ unless ( $exportmethod =~ /^[0-9a-z_]+$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($exportmethod =~ /^[0-9a-z_]+$/i) 0 1 1
118 0 croak( "Illegal export method name" );
119 }#unless
120 1 push( @EXPORT_OK, $exportmethod );
121 1 push( @{ $EXPORT_TAGS{std} }, $exportmethod );
122
123 {
124 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
125 1 ▶ *{ $exportmethod } = sub {
Subroutine __ANON__: not called CC=2 SCAR=14.6
126 0 ▶ unless ( $email->{params}->{__loaded} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($email->{"params"}{"__loaded"}) 0 0 0
127 0 $email->__LoadEmail();
128 }#unless
129 0 return $email;
130 }#sub
131 1 }#block
132
133 1 CGI::Application::Plugin::Email->export_to_level(1, @_);
134 }#sub
135
136
137
138 package CGI::Application::Plugin::Email::guts;
139
140
141 1 ▶sub new__ {
Subroutine new__: called CC=1 SCAR=0.0
142 1 my $class = shift;
143 1 my $obj = {};
144 1 bless( $obj, $class );
145 1 return $obj;
146 }#sub
147
148
149 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
150 0 shift;
151 0 return Email::Stuff->new( @_ );
152 }#sub
153
154
155 0 ▶sub __LoadEmail {
Subroutine __LoadEmail: not called CC=1 SCAR=6.9
156 0 require Email::Stuff;
157 0 import Email::Stuff;
158 }#sub
159
160
161 2 1;
↑ Summary