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