File Coverage

lib/Mail/AuthenticationResults/Token/String.pm
Criterion Covered Total %
statement 41 41 100.0
branch 22 26 84.6
condition 20 30 66.6
subroutine 6 6 100.0
pod 2 2 100.0
total 91 105 86.6


line stmt bran cond sub pod time code
1             package Mail::AuthenticationResults::Token::String;
2             # ABSTRACT: Class for modelling AuthenticationResults Header parts detected as strings
3              
4             require 5.008;
5 31     31   627 use strict;
  31         55  
  31         2930  
6 31     31   239 use warnings;
  31         2567  
  31         4780  
7             our $VERSION = '2.20260216'; # VERSION
8 31     31   8446 use Carp;
  31         57  
  31         2005  
9              
10 31     31   289 use base 'Mail::AuthenticationResults::Token';
  31         45  
  31         17526  
11              
12              
13             sub is {
14 4486     4486 1 6822 my ( $self ) = @_;
15 4486         10706 return 'string';
16             }
17              
18             sub parse {
19 657     657 1 1045 my ($self) = @_;
20              
21 657         1020 my $header = $self->{ 'header' };
22 657         1013 my $value = q{};
23              
24 657 100       1629 croak 'Not a string' if $header =~ /^"/;
25 656 100       1553 croak 'Not a string' if $header =~ /^\(/;
26              
27             # Parse differently if we are post assignment (we are a value) or not (we are likely a key or key part)
28 655         918 my $is_value = 0;
29 655         877 my $is_first = 0;
30 655 100       1466 if ( exists ( $self->{ 'args' }->{ 'last_non_comment_type' } ) ) {
31 594 100       1351 if ( $self->{ 'args' }->{ 'last_non_comment_type' }->is() eq 'assignment' ) {
32 326 100       972 if ( $self->{ 'args' }->{ 'last_non_comment_type' }->value() eq '=' ) {
33 243         404 $is_value = 1;
34             }
35             }
36             }
37             else {
38 61         102 $is_first = 1;
39             }
40              
41 655         1676 while ( length $header > 0 ) {
42 5364         7605 my $first = substr( $header,0,1 );
43 5364 100       10775 last if $first =~ /\s/;
44 5159 100       10786 last if $first eq ';';
45 5061 0 33     9058 last if $first eq '"' && ! $is_value && ! $is_first;
      33        
46 5061 0 33     9027 last if $first eq '(' && ! $is_value && ! $is_first;
      33        
47 5061 100 100     10077 last if $first eq '=' && ! $is_value && ! $is_first;
      66        
48 4822 100 100     8731 last if $first eq '/' && ! $is_value && ! $is_first;
      66        
49 4821 100 100     9279 last if $first eq '.' && ! $is_value && ! $is_first;
      100        
50              
51 4745         6326 $value .= $first;
52 4745         11631 $header = substr( $header,1 );
53             }
54              
55 655 100       1379 croak 'Not a string' if $value eq q{};
56              
57 649         1584 $self->{ 'value' } = $value;
58 649         4066 $self->{ 'header' } = $header;
59              
60 649         1523 return;
61             }
62              
63             1;
64              
65             __END__