blib/lib/Egg/View/Mail/Base.pm

filter: Statementstmt 29.5% 21 / 71 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 40.0% 6 / 15 Podpod 100% 7 / 7 totaltotal 24.8% 34 / 137 CC 20 SCAR 33.2
CC
20
Cov
20%
__init_mailbody
72.0
setup_mailer
42.0
setup_plugin
12.0
CRAP 27.7
« blib/lib/Egg/View/Mail/Plugin/EmbAgent.pm ↑ Summary blib/lib/Egg/View/Mail/Mailer/CMD.pm »
1 package Egg::View::Mail::Base;
2 #
3 # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
4 #
5 # $Id: Base.pm 328 2008-04-17 13:16:47Z lushe $
6 #
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use base qw/ Egg::Base Egg::Component /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our $VERSION = '0.03';
13  
14 0 ▶sub setup_plugin {
Subroutine setup_plugin: not called CC=3 SCAR=24.8
Pod documented
15 0 my $class= shift;
16 $class->isa_register(1, "Egg::View::Mail::Plugin::$_")
17 0 ▶ for (ref($_[0]) eq 'ARRAY' ? @{$_[0]}: @_);
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 0 0
18 0 $class->isa_terminator(__PACKAGE__);
19 0 $class;
20 }
21 0 ▶sub setup_mailer {
Subroutine setup_mailer: not called CC=6 SCAR=37.4
Pod documented
22 0 my $class = shift;
23 0 ▶ my $m_name= shift || croak q{I want mailer name.};
Condition0%0/2
shift() || croak('I want mailer name.')
l!l
00
MC/DC0%0/1
shift() || croak('I want mailer name.')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
24 0 my @comps;
25 0 ▶ if (@_) { push @comps, $_ for (ref($_[0]) eq 'ARRAY' ? @{$_[0]}: @_) }
Branch: 2 branches
BranchTrueFalseTotal
if (@_) 0 0 0
ref $_[0] eq 'ARRAY' ? : 0 0 0
26 $class->isa_register
27 0 (1, $_, "Egg::View::Mail::$_") for (@comps, "Mailer::$m_name");
28 0 $class->isa_terminator(__PACKAGE__);
29 0 $class;
30 }
31 0 ▶sub setup_template {
Subroutine setup_template: not called CC=3 SCAR=18.7
Pod documented
32 0 my $class = shift;
33 0 ▶ my $view_name= shift || croak q{I want view name.};
Condition0%0/2
shift() || croak('I want view name.')
l!l
00
MC/DC0%0/1
shift() || croak('I want view name.')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
34 0 ▶ my $template = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
35 0 $class->mk_classdata('default_template');
36 0 $class->default_template($template);
37 2 ▶ no strict 'refs'; ## no critic.
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
39 0 *{"${class}::___view"}=
40 0 ▶ sub { $_[0]->{___view} ||= $_[0]->e->view($view_name) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
$_[0]{"___view"} ||= $_[0]->e->view($view_name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]{"___view"} ||= $_[0]->e->view($view_name)
$_[0]{"___view"} $_[0]->e->view($view_name)
Truth table0%0/3
A ||= B
A= $_[0]{"___view"}B= $_[0]->e->view($view_name)
ABresult
1X1
011
000
41 0 $class;
42 }
43 0 ▶sub send {
Subroutine send: not called CC=1 SCAR=6.9
Pod documented
44 0 my $self= shift;
45 0 $self->mail_send( $self->create_mail_data(@_) );
46 }
47 0 ▶sub create_mail_data {
Subroutine create_mail_data: not called CC=3 SCAR=24.8
Pod documented
48 0 my $self= shift;
49 0 my $data= { %{$self->config},
50 0 ▶ %{ $_[0] ? ($_[1] ? {@_}: $_[0]) : croak q{I want mail data.} },
Branch: 2 branches
BranchTrueFalseTotal
$_[0] ? : 0 0 0
$_[1] ? : 0 0 0
51 };
52 0 $data->{body}= $self->create_mail_body($data);
53 0 $data;
54 }
55 0 ▶sub create_mail_body {
Subroutine create_mail_body: not called CC=1 SCAR=6.9
Pod documented
56 0 my($self, $data)= @_;
57 0 \<<END_BODY;
58 0 @{[ $self->create_mail_header($data) ]}
59 0 @{[ ${$self->__get_mailbody($data)} ]}
60 END_BODY
61 }
62 0 ▶sub create_mail_header {
Subroutine create_mail_header: not called CC=1 SCAR=6.9
Pod documented
63 0 my($self, $data)= @_;
64 0 <<END_HEADER;
65 Content-Type: text/plain
66 To: $data->{to}
67 From: $data->{from}
68 Subject: $data->{subject}
69 X-Mailer: $data->{x_mailer}
70 END_HEADER
71 }
72 0 ▶sub __init_mailbody {
Subroutine __init_mailbody: not called CC=8 SCAR=42.8
73 0 my($self, $data)= @_;
74 return ($data->{template} or ! $data->{body}) ? do {
75 0 ▶ $self->can('___view')
Branch: 1 branch
BranchTrueFalseTotal
$self->can("___view") or croak("I want setup of 'setup_template' method.") 0 0 0
76 || croak q{I want setup of 'setup_template' method.};
77 0 my $param= { %{$self->config}, %$data };
78 0 ▶ my $tmpl = $data->{template} || $self->default_template
Condition0%0/5
$data->{'template'} || $self->default_template || croak(q[I want 'template'.])
l!l
00
$data->{"template"} or $self->default_template
l!l&&r!l&&!r
000
MC/DC0%0/2
$data->{'template'} || $self->default_template || croak(q[I want 'template'.])
$data->{"template"} $self->default_template
Truth table0%0/3
A or B
A= $data->{"template"}B= $self->default_template
ABresult
1X1
011
000
79 || croak q{I want 'template'.};
80 0 my $view= $self->___view;
81 0 @{$view->params}{keys %$param}= values %$param;
82 0 $view->render($tmpl);
83 0 ▶ }: do {
Branch: 1 branch
BranchTrueFalseTotal
$data->{'template'} || !$data->{'body'} ? : 0 0 0
Condition0%0/3
$data->{"template"} or not $data->{"body"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$data->{"template"} or not $data->{"body"}
$data->{"template"} not $data->{"body"}
Truth table0%0/3
A or not(B)
A= $data->{"template"}B= not $data->{"body"}
ABresult
1X1
011
000
84 0 ▶ ref($data->{body}) eq 'ARRAY' ? \join "\n\n", @{$data->{body}}
Branch: 1 branch
BranchTrueFalseTotal
ref $data->{'body'} eq 'SCALAR' ? : 0 0 0
85 0 ▶ : ref($data->{body}) eq 'SCALAR' ? $data->{body} : \$data->{body};
Branch: 1 branch
BranchTrueFalseTotal
ref $data->{'body'} eq 'ARRAY' ? : 0 0 0
86 };
87 }
88 2 *__get_mailbody= \&__init_mailbody;
89  
90 2 1;
91  
92 __END__
« blib/lib/Egg/View/Mail/Plugin/EmbAgent.pm ↑ Summary blib/lib/Egg/View/Mail/Mailer/CMD.pm »