File Coverage

blib/lib/Egg/View/Mail.pm
Criterion Covered Total %
statement 15 50 30.0
branch 0 10 0.0
condition 0 21 0.0
subroutine 5 9 55.5
pod n/a
total 20 90 22.2


line stmt bran cond sub pod time code
1             package Egg::View::Mail;
2             #
3             # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
4             #
5             # $Id: Mail.pm 285 2008-02-28 04:20:55Z lushe $
6             #
7 2     2   669 use strict;
  2         3  
  2         504  
8 2     2   11 use warnings;
  2         3  
  2         179  
9              
10             our $VERSION = '0.01';
11              
12             sub _setup {
13 0     0     my($class, $e)= @_;
14 0           Egg::View::Mail::handler->_setup($e);
15 0           $class->next::method($e);
16             }
17              
18             package Egg::View::Mail::handler;
19 2     2   9 use strict;
  2         3  
  2         241  
20              
21             sub new {
22 0     0     my($class, $e, $c, $default)= @_;
23 0           my $pkg= $e->project_name. '::View::Mail';
24 0           $e->view_manager->context($pkg->default);
25             }
26             sub _setup {
27 0     0     my($class, $e)= @_;
28 0           my $base= $e->project_name. '::View::Mail';
29 0           my $path= $e->path_to(qw{ lib_project View/Mail });
30 2     2   9 no strict 'refs'; ## no critic.
  2         3  
  2         53  
31 2     2   10 no warnings 'redefine';
  2         8  
  2         1161  
32 0           push @{"${base}::ISA"}, 'Egg::Base';
  0            
33 0           $base->mk_classdata($_) for qw/ default labels /;
34 0           my $labels= $base->labels($e->ixhash);
35 0           for (sort (grep /.+\.pm$/, <$path/*>)) { ## no critic.
36 0 0         m{([^\\\/\:]+)\.pm$} || next;
37 0           my $name = $1;
38 0           my $dc = "${base}::$name";
39 0           my $c= $class->_init_config($e, $dc);
40 0   0       my $label= lc( $c->{label_name} || "Mail::$name" );
41 0           $e->view_manager->add_register(0, $label, $dc);
42 0 0         $base->default($label) if $c->{default};
43 0           $labels->{$label}= $dc;
44 0           $dc->_setup($e);
45             }
46 0 0         %$labels || die __PACKAGE__. q{ - The Mail controller is not found.};
47 0 0         $base->default((keys %$labels)[0]) unless $base->default;
48 0           @_;
49             }
50             sub _init_config {
51 0     0     my($class, $e, $dc)= @_;
52 0 0         $dc->require or die $@;
53 0   0       my $c= $dc->config || die __PACKAGE__. qq{ - '$dc' config is empty.};
54 0   0       $c->{mydomain} ||= $ENV{HOSTNAME} || 'localhost';
      0        
55 0   0       $c->{to} ||= $e->lc_namespace. "\@$c->{mydomain}";
56 0   0       $c->{from} ||= $e->lc_namespace. "\@$c->{mydomain}";
57 0   0       $c->{subject} ||= "Hellow !!";
58 0   0       $c->{x_mailer} ||= "Egg::View::Mail v$VERSION";
59 0           $c;
60             }
61              
62             1;
63              
64             __END__
65              
66             =head1 NAME
67              
68             Egg::View::Mail - View to transmit mail.
69              
70             =head1 SYNOPSIS
71              
72             my $mail= $e->view('mail_label');
73            
74             # Mail is transmitted.
75             $mail->send( to => 'hoge@booo.domain', body => <<END_BODY );
76             Hello. !!
77             END_BODY
78              
79             =head1 DESCRIPTION
80              
81             It is a view to transmit mail.
82              
83             To use it, the module is generated under the control of the project with the
84             helper.
85              
86             see L<Egg::Helper::View::Mail>.
87              
88             % cd /path/to/MyApp/bin
89             % ./egg_helper V::Mail [MODULE_NAME]
90              
91             'MyApp/View/Mail/MODULE_NAME.pm' is generated to the lib directory of the project
92             with this.
93              
94             And, 'Mail' is added to the VIEW setting of the project.
95              
96             % vi /path/to/MyApp/lib/MyApp/config.pm
97             .........
98             ...
99             VIEW => ['Mail'],
100              
101             The controller module generated when the project is started by this is set up
102             and using it becomes possible.
103              
104             =head1 HOW TO MAIL CONTROLLER
105              
106             The behavior at Mail Sending etc. can be customized by customizing the controller
107             module generated in the helper script.
108              
109             % vi /path/to/MyApp/lib/MyApp/View/Mail/Hoo.pm
110             package MyApp::View::Mail::Hoo;
111             use base qw/ Egg::View::Mail::Base /;
112            
113             __PACKAGE__->config( ..... );
114            
115             __PACKAGE__->setup_plugin( ...... );
116            
117             __PACKAGE__->setup_mailer( ...... );
118            
119             __PACKAGE__->setup_template( ....... );
120            
121             1;
122              
123             First of all, a necessary setting is done by 'config' method.
124              
125             And, the plugin component is set up if necessary by 'setup_plugin'.
126              
127             The name that omits the part of 'Egg::View::Mail::Plugin' is passed to the argument
128             by the list.
129              
130             __PACKAGE__->setup_plugin(qw/
131             EmbAgent
132             PortCheck
133             Lot
134             /;
135              
136             There is a thing that doesn't operate normally by the different opinion relation
137             because there is the one to Orbaraid the same method according to the loaded
138             plugin, too. In this case, please adjust the loading order and solve it.
139              
140             Next, it is loading of Mailer system component.
141              
142             __PACKAGE__->setup_mailer('CMD');
143              
144             L<Egg::View::Mail::Mailer::CMD> and L<Egg::View::Mail::Mailer::SMTP> are enclosed
145             with this package as Mailer system component.
146             Please use it properly by the use environment etc.
147              
148             To build in other components, the list is passed following Mailer system component.
149             The name that omits the part of 'Egg::View::Mail' is passed.
150              
151             __PACKAGE__->setup_mailer( SMTP => qw/
152             Encode::ISO2022JP
153             MIME::Entity
154             / );
155              
156             The different opinion problem occurs in order by which here is loaded.
157              
158             When the template is used, PATH of the template used by the label name and the
159             default of the template engine used by 'setup_template' method is set.
160              
161             __PACKAGE__->setup_template( Mason => 'mail/value.tt' );
162              
163             The MAIL controller is not a necessary translation in each template.
164             The purpose is to default of passing neither 'body' nor 'template' by 'send'
165             method until becoming empty and to use it.
166              
167             The object can be acquired in the label name set for the MAIL controller to be
168             built into the project.
169              
170             my $mail= $e->view('mail_label_name');
171              
172             =head1 CONFIGURATION
173              
174             Please refer to the document of the module for a setting necessary in each
175             component.
176              
177             =head3 label_name
178              
179             Label name to acquire MAIL controller object.
180              
181             Default is 'mail:: MODULE_NAME'.
182              
183             =head3 default
184              
185             It defaults to the MAIL controller who set it and it treats.
186              
187             There is especially not handling two or more MAIL controllers needing.
188              
189             It is set when this setting is not in any when there are two or more MAIL
190             controllers either by the result of sorting by the module name.
191              
192             =head3 to
193              
194             Mail Sending used by default ahead.
195              
196             It comes to be able to set two or more destinations with ARRAY by using
197             L<Egg::View::Mail::Plugin::Lot>.
198              
199             =head3 from
200              
201             Mail source who uses it by default.
202              
203             =head3 subject
204              
205             Subject of mail used by default.
206              
207             =head3 replay_to
208              
209             Content of 'Reply-To' header.
210              
211             =head3 return_path
212              
213             Content of 'Return-Path' header.
214              
215             =head3 cc
216              
217             Content of 'CC' header.
218              
219             =head3 bcc
220              
221             Content of 'BCC' header.
222              
223             =head3 x_mailer
224              
225             Content of 'X-Mailer' header.
226              
227             Default is 'Egg::View::Mail v[VERSION]'.
228              
229             =head3 mydomain
230              
231             It uses it to make the address of default.
232             It is not necessary if 'to' and 'from' are set.
233              
234             =head1 METHODS
235              
236             This module doesn't have the method that can be especially used.
237              
238             Please refer to the document of L<Egg::View::Mail::Base> of the MAIL controller
239             base class.
240              
241             =head2 new
242              
243             Constructor.
244              
245             The object of the MAIL controller of default is returned.
246              
247             my $mail= $e->view('mail');
248              
249             =head1 SEE ALSO
250              
251             L<Egg::Release>,
252             L<Egg::View::Mail::Base>,
253             L<Egg::View::Mail::Mailer::CMD>,
254             L<Egg::View::Mail::Mailer::SMTP>,
255             L<Egg::Helper::View::Mail>,
256              
257             =head1 AUTHOR
258              
259             Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
260              
261             =head1 COPYRIGHT AND LICENSE
262              
263             Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>, All Rights Reserved.
264              
265             This library is free software; you can redistribute it and/or modify
266             it under the same terms as Perl itself, either Perl version 5.8.6 or,
267             at your option, any later version of Perl 5 you may have available.
268              
269             =cut
270