blib/lib/Siesta.pm

filter: Statementstmt 100% 82 / 82 Branchbran 66.6% 12 / 18 Conditioncond 57.1% 8 / 14 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 17 / 17 Podpod 100% 7 / 7 totaltotal 86.3% 127 / 147 CC 17 SCAR 11.4
CC
17
Cov
89%
log
6.2
available_plugins
5.0
set_sender
3.1
CRAP 3.1
« blib/lib/Siesta/DBI.pm ↑ Summary blib/lib/Siesta/Plugin/MembersOnly.pm »
1 # $Id: Siesta.pm 1435 2003-10-17 13:35:50Z richardc $
2 package Siesta;
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use vars qw/$VERSION $tt/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 $VERSION = '0.66';
6  
7 27 ▶use Siesta::List;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 27 ▶use Siesta::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 27 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 27 ▶use File::Find::Rule qw/find/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 27 ▶use File::Basename qw/fileparse/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 27 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 27 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 27 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 =head1 NAME
19  
20 Siesta - the Siesta mailing list manager.
21  
22 =head1 METHODS
23  
24 =head2 ->new
25  
26 =cut
27  
28 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
29 1 my $referent = shift;
30 1 my %args = @_;
31 1 ▶ my $class = ref $referent || $referent;
Condition33%1/3
ref $referent || $referent
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $referent || $referent
ref $referent $referent
Truth table33%1/3
A || B
A= ref $referentB= $referent
ABresult
1X1
011
000
32  
33 1 my $storage = delete $args{storage};
34  
35 1 my $self = bless {}, $class;
36 1 $self->log("instantiated a Siesta", 7);
37 1 $self;
38 }
39  
40 =head2 ->process( mail => $message, action => $action, list => $list )
41  
42 process a mail
43  
44 action may be C<post>, C<sub>, or C<unsub>
45 defaults to C<post>
46  
47 mail must be either an anonymous array or a filehandle to read the
48 message body from
49  
50 list must be the identifier of a mailing list
51  
52 =cut
53  
54  
55 1 ▶sub process {
Subroutine process: called CC=2 SCAR=7.0
Pod documented
56 1 my $self = shift;
57 1 my %args = @_;
58 1 ▶ my $action = $args{action} || 'post';
Condition50%1/2
$args{'action'} || 'post'
l!l
10
MC/DC0%0/1
$args{'action'} || 'post'
$args{'action'}
Truth table50%1/2
A
A= $args{'action'}
Aresult
11
00
59 1 my $mail = Siesta::Message->new( $args{mail} );
60 1 my $list = Siesta::List->load( $args{list} );
61  
62 1 $self->log("processing $action", 1);
63 1 $mail->plugins( [ $list->plugins( $action ) ] );
64 1 $mail->process;
65 }
66  
67 27 my $sender;
68  
69 =head2 ->sender
70  
71 Return the current sender.
72  
73 The default is Siesta::Send::Sendmail.
74  
75 See B<set_sender> for other details.
76  
77 =cut
78  
79 14 ▶sub sender {
Subroutine sender: called CC=2 SCAR=7.6
Pod documented
80 14 ▶ $sender || Siesta->set_sender('Sendmail');
Branch: 1 branch
BranchTrueFalseTotal
$sender or "Siesta"->set_sender("Sendmail") 14 0 14
81 }
82  
83 =head2 ->set_sender ($class, @options)
84  
85 Set the current sender to the given class.
86 This will pass on any options you give it automatically.
87  
88 =cut
89  
90 18 ▶sub set_sender {
Subroutine set_sender: called CC=3 SCAR=11.2
Pod documented
91 18 my $self = shift;
92 18 my $class = shift;
93 18 ▶ return unless $class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 0 18 18
94  
95 18 $class = "Siesta::Send::$class";
96 18 ▶ $class->require
Branch: 1 branch
BranchTrueFalseTotal
$class->require or die "Couldn't require '${class}': $UNIVERSAL::require::ERROR" 18 0 18
97 or die "Couldn't require '$class': $UNIVERSAL::require::ERROR";
98 18 $sender = $class->new(@_);
99 }
100  
101 =head2 ->log ($message, $level)
102  
103 Log message as long as level is below the value set in
104 I<$Siesta::Config::LOG_LEVEL>;
105  
106 The lower the log level, the more important the error.
107  
108 The default is 3.
109  
110 =cut
111  
112 my $logger;
113  
114 42 ▶sub log {
Subroutine log: called CC=6 SCAR=18.2
Pod documented
115 42 my $self = shift;
116 42 ▶ my $message = shift
Branch: 1 branch
BranchTrueFalseTotal
my $message = shift() or croak("need a message to log") 42 0 42
117 or croak "need a message to log";
118  
119 42 ▶ my $level = shift || $Siesta::Config::LOG_LEVEL;
Condition66%2/3
shift() || $Siesta::Config::LOG_LEVEL
l!l&&r!l&&!r
32100
MC/DC0%0/2
shift() || $Siesta::Config::LOG_LEVEL
shift() $Siesta::Config::LOG_LEVEL
Truth table66%2/3
A || B
A= shift()B= $Siesta::Config::LOG_LEVEL
ABresult
1X1
011
000
120  
121 42 ▶ unless ($logger) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($logger) 15 27 42
122 15 ▶ $logger = IO::File->new(">>$Siesta::Config::LOG_PATH")
Branch: 1 branch
BranchTrueFalseTotal
$logger = "IO::File"->new(">>$Siesta::Config::LOG_PATH") or die "Couldn't open file $Siesta::Config::LOG_PATH for appending\n" 15 0 15
123 or die "Couldn't open file $Siesta::Config::LOG_PATH for appending\n";
124 }
125  
126 42 my $date = localtime;
127 42 ▶ print $logger "$date $message $level\n"
Branch: 1 branch
BranchTrueFalseTotal
if $level >= $Siesta::Config::LOG_LEVEL 24 18 42
128 if $level >= $Siesta::Config::LOG_LEVEL;
129 }
130  
131  
132 =head2 ->available_plugins
133  
134 Return the name of every plugin on the system.
135  
136 =cut
137  
138 1 ▶sub available_plugins {
Subroutine available_plugins: called CC=5 SCAR=16.1
Pod documented
139 1 my $self = shift;
140 1 my @dirs;
141  
142 1 foreach my $dir ( map { "$_/Siesta/Plugin" } @INC ) {
143 9 ▶ push @dirs, $dir if ( -e $dir && -d $dir );
Branch: 1 branch
BranchTrueFalseTotal
if -e $dir and -d $dir 3 6 9
Condition66%2/3
-e $dir and -d $dir
!ll&&!rl&&r
603
MC/DC50%1/2
-e $dir and -d $dir
-e $dir -d $dir
Truth table66%2/3
A and B
A= -e $dirB= -d $dir
ABresult
0X0
100
111
144 }
145  
146 1 my @files = find( name => "*.pm", in => \@dirs );
147 1 my @plugins;
148  
149 1 foreach my $file (@files) {
150 45 my ($name) = fileparse($file, qr{\.pm});
151 45 push @plugins, $name;
152 }
153  
154 1 my %plugins = map { $_ => 1 } @plugins;
155  
156 1 return sort keys %plugins;
157 }
158  
159 =head2 ->bake ( $template, $options )
160  
161 $options, if present, is a hash reference
162  
163 Returns the results of baking B<$template> with the variables
164 from B<$options> mixed in.
165  
166 =cut
167  
168 15 ▶sub bake {
Subroutine bake: called CC=3 SCAR=11.1
Pod documented
169 15 my $self = shift;
170 15 my $template = shift;
171  
172 15 my %opts = @_;
173  
174 15 ▶ $tt ||= Template->new({ INCLUDE_PATH => $Siesta::Config::MESSAGES });
Condition66%2/3
$Siesta::tt ||= "Template"->new({"INCLUDE_PATH", $Siesta::Config::MESSAGES})
l!l&&r!l&&!r
960
MC/DC0%0/2
$Siesta::tt ||= "Template"->new({"INCLUDE_PATH", $Siesta::Config::MESSAGES})
$Siesta::tt "Template"->new({"INCLUDE_PATH", $Siesta::Config::MESSAGES})
Truth table66%2/3
A ||= B
A= $Siesta::ttB= "Template"->new({"INCLUDE_PATH", $Siesta::Config::MESSAGES})
ABresult
1X1
011
000
175  
176 15 my $body;
177 15 ▶ $tt->process($template, \%opts, \$body)
Branch: 1 branch
BranchTrueFalseTotal
$Siesta::tt->process($template, \%opts, \$body) or die "Couldn't process message template\n '$Siesta::Config::ROOT/messages/${template}'\n because : ", $Siesta::tt->error 15 0 15
178 or die "Couldn't process message template
179 '${Siesta::Config::ROOT}/messages/$template'
180 because : ",$tt->error();
181  
182 15 return $body;
183 }
184  
185 =head1 COPYING
186  
187 Licensed under the same terms as Perl itself.
188  
189 =head1 SEE ALSO
190  
191 L<nacho>, L<tequila>, L<bandito>, L<Siesta::UserGuide>
192  
193 =cut
194  
195 27 1;
196  
« blib/lib/Siesta/DBI.pm ↑ Summary blib/lib/Siesta/Plugin/MembersOnly.pm »