File Coverage

blib/lib/Mail/Message/Field/Flex.pm
Criterion Covered Total %
statement 42 46 91.3
branch 17 20 85.0
condition 3 6 50.0
subroutine 11 13 84.6
pod 8 9 88.8
total 81 94 86.1


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution Mail-Message version 4.04.
2             # The POD got stripped from this file by OODoc version 3.06.
3             # For contributors see file ChangeLog.
4              
5             # This software is copyright (c) 2001-2026 by Mark Overmeer.
6              
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10              
11              
12             package Mail::Message::Field::Flex;{
13             our $VERSION = '4.04';
14             }
15              
16 3     3   7302 use parent 'Mail::Message::Field';
  3         10  
  3         23  
17              
18 3     3   254 use strict;
  3         8  
  3         68  
19 3     3   14 use warnings;
  3         22  
  3         200  
20              
21 3     3   16 use Log::Report 'mail-message', import => [ qw// ];
  3         7  
  3         24  
22              
23             #--------------------
24              
25             sub new($;$$@)
26 18     18 1 162843 { my $class = shift;
27             my $args
28             = @_ <= 2 || ! ref $_[-1] ? {}
29 18 50 66     76 : ref $_[-1] eq 'ARRAY' ? { @{pop @_} }
  1 100       4  
30             : pop @_;
31              
32 18 100       85 my ($name, $body) = $class->consume(@_==1 ? (shift) : (shift, shift));
33 18 50       40 defined $body or return ();
34              
35             # Attributes preferably stored in array to protect order.
36 18         26 my $attr = $args->{attributes};
37 18 50 33     60 $attr = [ %$attr ] if defined $attr && ref $attr eq 'HASH';
38 18         26 push @$attr, @_;
39              
40 18         122 $class->SUPER::new(%$args, name => $name, body => $body, attributes => $attr);
41             }
42              
43             sub init($)
44 18     18 0 33 { my ($self, $args) = @_;
45              
46 18         147 @$self{ qw/MMFF_name MMFF_body/ } = @$args{ qw/name body/ };
47 18 100       48 $self->comment($args->{comment}) if exists $args->{comment};
48              
49 18         29 my $attr = $args->{attributes};
50 18         70 $self->attribute(shift @$attr, shift @$attr) while @$attr;
51              
52 18         95 $self;
53             }
54              
55             sub clone()
56 0     0 1 0 { my $self = shift;
57 0         0 (ref $self)->new($self->Name, $self->body);
58             }
59              
60             sub length()
61 0     0 1 0 { my $self = shift;
62 0         0 length($self->{MMFF_name}) + 1 + length($self->{MMFF_body});
63             }
64              
65 27     27 1 99 sub name() { lc($_[0]->{MMFF_name}) }
66              
67 5     5 1 18 sub Name() { $_[0]->{MMFF_name} }
68              
69             sub folded(;$)
70 8     8 1 10 { my $self = shift;
71              
72             wantarray
73 8 100       47 or return $self->{MMFF_name}.':'.$self->{MMFF_body};
74              
75 2         5 my @lines = $self->foldedBody;
76 2         5 my $first = $self->{MMFF_name}. ':'. shift @lines;
77 2         7 ($first, @lines);
78             }
79              
80             sub unfoldedBody($;@)
81 39     39 1 4613 { my $self = shift;
82 39 100       84 $self->{MMFF_body} = $self->fold($self->{MMFF_name}, @_) if @_;
83 39         103 $self->unfold($self->{MMFF_body});
84             }
85              
86             sub foldedBody($)
87 13     13 1 39 { my ($self, $body) = @_;
88 13 100       37 if(@_==2) { $self->{MMFF_body} = $body }
  3         9  
89 10         24 else { $body = $self->{MMFF_body} }
90              
91 13 100       65 wantarray ? (split /^/, $body) : $body;
92             }
93              
94             1;