| 1 | package MIME::Expander; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use vars qw($PrefixGuess $PrefixPlugin @DefaultGuesser @EnabledPlugins); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | $PrefixGuess = 'MIME::Expander::Guess'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | $PrefixPlugin = 'MIME::Expander::Plugin'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | @DefaultGuesser = ('MMagic', 'FileName'); | |||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | @EnabledPlugins = (); | |||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Email::MIME; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use Email::MIME::ContentType (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use MIME::Type; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use Module::Load; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use Module::Pluggable search_path => $PrefixPlugin, sub_name => 'expanders'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use MIME::Expander::Plugin::MessageRFC822; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | @EnabledPlugins = @_; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 349 | ▶ | sub regulate_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
regulate_type: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 349 | ▶ | return undef unless( defined $_[1] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 301 | my $type = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # There is regexp from Email::MIME::ContentType 1.015 | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 301 | my $tspecials = quotemeta '()<>@,;:\\"/[]?='; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 301 | my $discrete = qr/[^$tspecials]+/; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 301 | my $composite = qr/[^$tspecials]+/; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 301 | my $params = qr/;.*/; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 301 | ▶ | return undef unless( $type =~ m[ ^ ($discrete) / ($composite) \s* ($params)? $ ]x ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 299 | my $ct = Email::MIME::ContentType::parse_content_type($type); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 299 | ▶ | return undef if( ! $ct->{discrete} or ! $ct->{composite} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ct->{"discrete"} and $ct->{"composite"}
MC/DC0%0/2
$ct->{"discrete"} and $ct->{"composite"}
$ct->{"discrete"}
$ct->{"composite"}
Truth table33%1/3
A and B
A= $ct->{"discrete"}B= $ct->{"composite"}
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 299 | return MIME::Type->simplified(join('/',$ct->{discrete}, $ct->{composite})); | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 18 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 18 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 18 | ▶ | $class = ref $class || $class; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 18 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 49 | expects => [], | ||||||||||||||||||||||||||||||||||||||||||
| 50 | guesser => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | depth => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 18 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 18 | return $self->init(@_); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 22 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 22 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 22 | my $args; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 22 | ▶ | if( 0 == @_ % 2 ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 19 | $args = { @_ } | |||||||||||||||||||||||||||||||||||||||||
| 62 | }else{ | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | ▶ | $args = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | $self->expects( | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 22 | ▶ | exists $args->{expects} ? $args->{expects} : [] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | $self->guesser( | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 22 | ▶ | exists $args->{guesser} ? $args->{guesser} : undef ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | $self->depth( | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 22 | ▶ | exists $args->{depth} ? $args->{depth} : undef ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 22 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 144 | ▶ | sub expects { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expects: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 144 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 144 | ▶ | if( @_ ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 27 | $self->{expects} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 82 | die "setting value is not acceptable, it requires an reference of ARRAY" | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 27 | ▶ | if( defined $self->{expects} and ref($self->{expects}) ne 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->{"expects"} and ref $self->{"expects"} ne "ARRAY"
MC/DC100%2/2
defined $self->{"expects"} and ref $self->{"expects"} ne "ARRAY"
defined $self->{"expects"}
ref $self->{"expects"} ne "ARRAY"
Truth table100%3/3
A and B
A= defined $self->{"expects"}B= ref $self->{"expects"} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 143 | return $self->{expects}; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 61 | ▶ | sub is_expected { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_expected: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 61 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 61 | ▶ | my $type = shift or undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 61 | ▶ | die "invalid type $type that has not looks as mime/type" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | if( $type !~ m,^.+/.+$, ); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 60 | ▶ | return () unless( $self->expects ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 55 | ▶ | for my $regexp ( map { ref $_ ? $_ : qr/$_/ } @{$self->expects} ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 33 | ▶ | return 1 if( $type =~ $regexp ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 46 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 57 | ▶ | sub depth { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
depth: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 57 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 57 | ▶ | if( @_ ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 26 | $self->{depth} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 104 | die "setting value is not acceptable, it requires a native number" | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 26 | ▶ | if( defined $self->{depth} and $self->{depth} =~ /\D/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->{"depth"} and $self->{"depth"} =~ /\D/
MC/DC100%2/2
defined $self->{"depth"} and $self->{"depth"} =~ /\D/
defined $self->{"depth"}
$self->{"depth"} =~ /\D/
Truth table100%3/3
A and B
A= defined $self->{"depth"}B= $self->{"depth"} =~ /\D/
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 56 | return $self->{depth}; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 83 | ▶ | sub guesser { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
guesser: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 83 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 83 | ▶ | if( @_ ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 27 | $self->{guesser} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 114 | die "setting value is not acceptable, it requires an reference of CODE or ARRAY" | ||||||||||||||||||||||||||||||||||||||||||
| 115 | if( defined $self->{guesser} | ||||||||||||||||||||||||||||||||||||||||||
| 116 | and ref($self->{guesser}) ne 'CODE' | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 27 | ▶ | and ref($self->{guesser}) ne 'ARRAY'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $self->{"guesser"} and ref $self->{"guesser"} ne "CODE" and ref $self->{"guesser"} ne "ARRAY"
defined $self->{"guesser"} and ref $self->{"guesser"} ne "CODE"
MC/DC100%3/3
defined $self->{"guesser"} and ref $self->{"guesser"} ne "CODE" and ref $self->{"guesser"} ne "ARRAY"
defined $self->{"guesser"}
ref $self->{"guesser"} ne "CODE"
ref $self->{"guesser"} ne "ARRAY"
Truth table100%4/4
A and B and C
A= defined $self->{"guesser"}B= ref $self->{"guesser"} ne "CODE"C= ref $self->{"guesser"} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 82 | return $self->{guesser}; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 51 | ▶ | sub guess_type_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
guess_type_of: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 51 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 51 | ▶ | my $ref_data = shift or die "missing mandatory parameter"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 51 | ▶ | my $info = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 51 | my $type = undef; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 51 | my $routine = $self->guesser; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 51 | ▶ | if( ref $routine eq 'CODE' ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | $type = $self->guesser->($ref_data, $info); | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | }else{ | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 49 | my @routines; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 49 | ▶ | if( ref $routine eq 'ARRAY' ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | @routines = @$routine; | |||||||||||||||||||||||||||||||||||||||||
| 137 | }else{ | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 47 | @routines = @DefaultGuesser; | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 49 | for my $klass ( @routines ){ | |||||||||||||||||||||||||||||||||||||||||
| 141 | 50 | ▶ | $klass = join('::', $PrefixGuess, $klass) if( $klass !~ /:/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 50 | Module::Load::load $klass; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 50 | $type = $self->regulate_type( $klass->type($ref_data, $info) ); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 50 | ▶ | last if( $type and $type ne 'application/octet-stream'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type and $type ne "application/octet-stream"
MC/DC50%1/2
$type and $type ne "application/octet-stream"
$type
$type ne "application/octet-stream"
Truth table66%2/3
A and B
A= $typeB= $type ne "application/octet-stream"
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 51 | ▶ | return ($type || 'application/octet-stream'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$type || 'application/octet-stream'
MC/DC100%1/1
$type || 'application/octet-stream'
$type
Truth table100%2/2
A
A= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 50 | ▶ | sub plugin_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plugin_for: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 50 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 50 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 50 | my $plugin = undef; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 50 | for my $available ( $self->expanders ){ | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 203 | my $klass = undef; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 203 | ▶ | unless( @EnabledPlugins ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 195 | $klass = $available; | |||||||||||||||||||||||||||||||||||||||||
| 160 | }else{ | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 8 | for my $enable ( @EnabledPlugins ){ | |||||||||||||||||||||||||||||||||||||||||
| 162 | 8 | ▶ | $enable = join('::', $PrefixPlugin, $enable) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | if( $enable !~ /:/ ); | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 8 | ▶ | if( $available eq $enable ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | $klass = $available; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 8 | ▶ | next unless( $klass ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 197 | Module::Load::load $klass; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 197 | ▶ | if( $klass->is_acceptable( $self->regulate_type($type) ) ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 24 | $plugin = $klass->new; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 24 | last; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 50 | return $plugin; | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 45 | ▶ | sub create_media { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_media: called CC=6 SCAR=18.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 45 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 45 | ▶ | my $ref_data = shift or die "missing mandatory parameter"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 45 | ▶ | my $info = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 45 | my $type = $self->regulate_type($info->{content_type}); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 45 | ▶ | if( ! $type or $type eq 'application/octet-stream' ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $type or $type eq "application/octet-stream"
MC/DC0%0/2
not $type or $type eq "application/octet-stream"
not $type
$type eq "application/octet-stream"
Truth table33%1/3
not(A) or B
A= not $typeB= $type eq "application/octet-stream"
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 45 | $type = $self->guess_type_of($ref_data, $info); | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 45 | ▶ | if( MIME::Expander::Plugin::MessageRFC822->is_acceptable( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | $self->regulate_type($type) | ||||||||||||||||||||||||||||||||||||||||||
| 193 | )){ | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 3 | return Email::MIME->new($ref_data); | |||||||||||||||||||||||||||||||||||||||||
| 195 | }else{ | ||||||||||||||||||||||||||||||||||||||||||
| 196 | return Email::MIME->create( | ||||||||||||||||||||||||||||||||||||||||||
| 197 | attributes => { | ||||||||||||||||||||||||||||||||||||||||||
| 198 | content_type => $type, | ||||||||||||||||||||||||||||||||||||||||||
| 199 | encoding => 'binary', | ||||||||||||||||||||||||||||||||||||||||||
| 200 | filename => $info->{filename}, | ||||||||||||||||||||||||||||||||||||||||||
| 201 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 42 | body => $ref_data, | |||||||||||||||||||||||||||||||||||||||||
| 203 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 9 | ▶ | sub walk { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
walk: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 9 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 9 | my $callback = shift; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 9 | ▶ | my $info = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 9 | my $c = 0; | |||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 9 | my @medias = (); | |||||||||||||||||||||||||||||||||||||||||
| 215 | 9 | ▶ | if( blessed($data) and $data->isa('Email::Simple') ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($data) and $data->isa("Email::Simple")
MC/DC50%1/2
builtin::blessed($data) and $data->isa("Email::Simple")
builtin::blessed($data)
$data->isa("Email::Simple")
Truth table66%2/3
A and B
A= builtin::blessed($data)B= $data->isa("Email::Simple")
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | push @medias, $data; | |||||||||||||||||||||||||||||||||||||||||
| 217 | }else{ | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 8 | ▶ | @medias = ($self->create_media( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | ref $data eq 'SCALAR' ? $data : \$data, | ||||||||||||||||||||||||||||||||||||||||||
| 220 | $info)); | ||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | # reset vars for depth option | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 9 | my $ptr = 0; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 9 | my $limit = 0; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 9 | my $level = 1; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 9 | my $bound = scalar @medias; | |||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | # when expandable contents, then append it to @medias | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 9 | ▶ | while( my $media = shift @medias ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 46 | my $type = $media->content_type; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 46 | my $plugin = $self->plugin_for($type); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 46 | ▶ | if( $limit or $self->is_expected( $type ) or ! $plugin ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$limit or $self->is_expected($type) or not $plugin
$limit or $self->is_expected($type)
MC/DC100%3/3
$limit or $self->is_expected($type) or not $plugin
$limit
$self->is_expected($type)
not $plugin
Truth table100%4/4
A or B or not(C)
A= $limitB= $self->is_expected($type)C= not $plugin
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | # expected or un-expandable data | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 28 | ▶ | $callback->($media) if( ref $callback eq 'CODE' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 28 | ++$c; | |||||||||||||||||||||||||||||||||||||||||
| 237 | }else{ | ||||||||||||||||||||||||||||||||||||||||||
| 238 | # expand more | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 37 | ▶ | $plugin->expand( $media , sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 37 | push @medias, $self->create_media( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 241 | 18 | }); | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 46 | ++$ptr; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 46 | ▶ | if( $bound <= $ptr ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 22 | ▶ | if( $self->depth and $self->depth <= $level ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->depth and $self->depth <= $level
MC/DC50%1/2
$self->depth and $self->depth <= $level
$self->depth
$self->depth <= $level
Truth table66%2/3
A and B
A= $self->depthB= $self->depth <= $level
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | $limit = 1; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 22 | $bound += scalar @medias; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 22 | ++$level; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 9 | return $c; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 259 | __END__ | ||||||||||||||||||||||||||||||||||||||||||