Courriel/Header/Disposition.pm

filter: Statementstmt 87.2% 48 / 55 Branchbran 25.0% 2 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 76.9% 10 / 13 Podpod n/a totaltotal 78.9% 60 / 76 CC 5 SCAR 13.1
CC
5
Cov
79%
__ANON__
12.0
__ANON__
6.0
__ANON__
2.0
CRAP 3.7
« Courriel/HeaderAttribute.pm ↑ Summary Courriel/Types/Internal.pm »
1 package Courriel::Header::Disposition;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 our $VERSION = '0.49';
8  
9 8 ▶use Courriel::Types qw( Bool Maybe NonEmptyStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use DateTime::Format::Mail;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 8 extends 'Courriel::Header';
17  
18 8 with 'Courriel::Role::HeaderWithAttributes' =>
19 { main_value_key => 'disposition' };
20  
21 8 has '+value' => (
22 required => 0,
23 lazy => 1,
24 builder => 'as_header_value',
25 );
26  
27 8 has disposition => (
28 is => 'ro',
29 isa => NonEmptyStr,
30 required => 1,
31 );
32  
33 has is_inline => (
34 is => 'ro',
35 isa => Bool,
36 init_arg => undef,
37 lazy => 1,
38 2 ▶ default => sub { $_[0]->disposition() ne 'attachment' },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 8 );
40  
41 has is_attachment => (
42 is => 'ro',
43 isa => Bool,
44 init_arg => undef,
45 lazy => 1,
46 0 ▶ default => sub { !$_[0]->is_inline() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 8 );
48  
49 has filename => (
50 is => 'ro',
51 isa => Maybe [NonEmptyStr],
52 init_arg => undef,
53 lazy => 1,
54 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
55 exists $_[0]->_attributes()->{filename}
56 ? $_[0]->_attributes()->{filename}->value()
57 0 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]->_attributes->{'filename'} ? : 0 0 0
58 },
59 8 );
60  
61 {
62 8 my $parser = DateTime::Format::Mail->new( loose => 1 );
63 8 for my $attr (qw( creation_datetime modification_datetime read_datetime ))
64 {
65 24 ( my $name_in_header = $attr ) =~ s/_/-/g;
66 24 $name_in_header =~ s/datetime/date/;
67  
68 0 ▶ my $default = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
69 0 my $attr = $_[0]->_attributes()->{$name_in_header};
70 0 ▶ return unless $attr;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr 0 0 0
71  
72 0 my $dt = $parser->parse_datetime( $attr->value() );
73 0 ▶ $dt->set_time_zone('UTC') if $dt;
Branch: 1 branch
BranchTrueFalseTotal
if $dt 0 0 0
74  
75 0 return $dt;
76 24 };
77  
78 24 has $attr => (
79 is => 'ro',
80 isa => Maybe ['DateTime'],
81 init_arg => undef,
82 lazy => 1,
83 default => $default,
84 );
85 }
86 }
87  
88 61 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
89 61 my $orig = shift;
90 61 my $class = shift;
91  
92 61 my $p = $class->$orig(@_);
93  
94 61 ▶ $p->{name} = 'Content-Disposition' unless exists $p->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $p->{"name"} 1 60 61
95  
96 61 return $p;
97 8 };
98  
99 8 __PACKAGE__->meta()->make_immutable();
100  
101 8 1;
102  
103 # ABSTRACT: The content disposition for an email part
104  
105 __END__
« Courriel/HeaderAttribute.pm ↑ Summary Courriel/Types/Internal.pm »