| 1 | package Silki::Email; | ||||||||||||
| 2 | { | ||||||||||||
| 3 | $Silki::Email::VERSION = '0.29'; | ||||||||||||
| 4 | } | ||||||||||||
| 5 | |||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 2 | ▶ | use Email::Date qw( format_date ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 2 | ▶ | use Email::MessageID; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 2 | ▶ | use Email::MIME::CreateHTML; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 2 | ▶ | use Email::Sender::Simple qw( sendmail ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 2 | ▶ | use HTML::Mason::Interp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 2 | ▶ | use HTML::TreeBuilder; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 2 | ▶ | use MooseX::Params::Validate qw( validated_list ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 2 | ▶ | use Silki::Config; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 2 | ▶ | use Silki::HTML::FormatText; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 2 | ▶ | use Silki::Schema::User; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 1 | ▶ | use Silki::Types qw( Str HashRef ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | |||||||||||||
| 21 | 1 | ▶ | use Sub::Exporter -setup => { exports => ['send_email'] }; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | |||||||||||||
| 23 | my $Body; | ||||||||||||
| 24 | my $Interp; | ||||||||||||
| 25 | |||||||||||||
| 26 | { | ||||||||||||
| 27 | my $config = Silki::Config->instance(); | ||||||||||||
| 28 | |||||||||||||
| 29 | my %config = ( | ||||||||||||
| 30 | comp_root => | ||||||||||||
| 31 | $config->share_dir()->subdir('email-templates')->stringify(), | ||||||||||||
| 32 | data_dir => | ||||||||||||
| 33 | $config->cache_dir()->subdir( 'mason', 'email' )->stringify(), | ||||||||||||
| 34 | error_mode => 'fatal', | ||||||||||||
| 35 | in_package => 'Silki::Mason::Email', | ||||||||||||
| 36 | ); | ||||||||||||
| 37 | |||||||||||||
| 38 | if ( $config->is_production() ) { | ||||||||||||
| 39 | $config{static_source} = 1; | ||||||||||||
| 40 | $config{static_source_touch_file} | ||||||||||||
| 41 | = $config->etc_dir()->file('mason-touch')->stringify(); | ||||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | $Interp = HTML::Mason::Interp->new( | ||||||||||||
| 45 | out_method => \$Body, | ||||||||||||
| 46 | %config, | ||||||||||||
| 47 | ); | ||||||||||||
| 48 | }; | ||||||||||||
| 49 | |||||||||||||
| 50 | 0 | ▶ | sub send_email { | ||||||||||
|
Subroutine
send_email: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 51 | 0 | my ( $from, $to, $subject, $template, $args ) = validated_list( | |||||||||||
| 52 | \@_, | ||||||||||||
| 53 | from => { | ||||||||||||
| 54 | isa => Str, | ||||||||||||
| 55 | default => Silki::Schema::User->SystemUser()->email_address(), | ||||||||||||
| 56 | }, | ||||||||||||
| 57 | to => { isa => Str }, | ||||||||||||
| 58 | subject => { isa => Str }, | ||||||||||||
| 59 | template => { isa => Str }, | ||||||||||||
| 60 | template_params => { | ||||||||||||
| 61 | isa => HashRef, | ||||||||||||
| 62 | default => {}, | ||||||||||||
| 63 | }, | ||||||||||||
| 64 | ); | ||||||||||||
| 65 | |||||||||||||
| 66 | 0 | my $html_body = _execute_template( $template, $args ); | |||||||||||
| 67 | |||||||||||||
| 68 | 0 | my $text_body = Silki::HTML::FormatText->new( leftmargin => 0 ) | |||||||||||
| 69 | ->format_string($html_body); | ||||||||||||
| 70 | |||||||||||||
| 71 | 0 | ▶ | my $version = $Silki::Email::VERSION || 'from working copy'; | ||||||||||
|
Condition0%0/2
$Silki::Email::VERSION || 'from working copy'
MC/DC0%0/1
$Silki::Email::VERSION || 'from working copy'
$Silki::Email::VERSION
Truth table0%0/2
A
A= $Silki::Email::VERSION
| |||||||||||||
| 72 | |||||||||||||
| 73 | 0 | my $email = Email::MIME->create_html( | |||||||||||
| 74 | header => [ | ||||||||||||
| 75 | From => $from, | ||||||||||||
| 76 | To => $to, | ||||||||||||
| 77 | Subject => $subject, | ||||||||||||
| 78 | 'Message-ID' => Email::MessageID->new()->in_brackets(), | ||||||||||||
| 79 | Date => format_date(), | ||||||||||||
| 80 | 'X-Sender' => "Silki version $version", | ||||||||||||
| 81 | ], | ||||||||||||
| 82 | body => $html_body, | ||||||||||||
| 83 | body_attributes => { content_type => 'text/html; charset=utf-8' }, | ||||||||||||
| 84 | text_body_attributes => | ||||||||||||
| 85 | { content_type => 'text/plain; charset=utf-8' }, | ||||||||||||
| 86 | text_body => $text_body, | ||||||||||||
| 87 | ); | ||||||||||||
| 88 | |||||||||||||
| 89 | 0 | sendmail($email); | |||||||||||
| 90 | |||||||||||||
| 91 | 0 | return; | |||||||||||
| 92 | } | ||||||||||||
| 93 | |||||||||||||
| 94 | 0 | ▶ | sub _execute_template { | ||||||||||
|
Subroutine
_execute_template: not called CC=1 SCAR=6.9
| |||||||||||||
| 95 | 0 | my $template = shift; | |||||||||||
| 96 | 0 | my $args = shift; | |||||||||||
| 97 | |||||||||||||
| 98 | 0 | $Body = q{}; | |||||||||||
| 99 | 0 | $Interp->exec( q{/} . $template . '.html', %{$args} ); | |||||||||||
| 100 | |||||||||||||
| 101 | 0 | return $Body; | |||||||||||
| 102 | } | ||||||||||||
| 103 | |||||||||||||
| 104 | { | ||||||||||||
| 105 | package Silki::Mason::Email; | ||||||||||||
| 106 | { | ||||||||||||
| 107 | $Silki::Mason::Email::VERSION = '0.29'; | ||||||||||||
| 108 | } | ||||||||||||
| 109 | |||||||||||||
| 110 | 1 | ▶ | use Silki::I18N qw( loc ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 111 | 1 | ▶ | use Silki::Util qw( string_is_empty ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 112 | } | ||||||||||||
| 113 | |||||||||||||
| 114 | 1; | ||||||||||||
| 115 | |||||||||||||
| 116 | # ABSTRACT: Sends email from a template | ||||||||||||
| 117 | |||||||||||||
| 118 | __END__ | ||||||||||||