« lib/Mail/AuthenticationResults/Header/Base.pm
↑ Summary
lib/Mail/AuthenticationResults/FoldableHeader.pm »
| 1 | package Mail::AuthenticationResults::Parser; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Class for parsing Authentication Results Headers | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 25 | require 5.008; | |||||||||||||||||||||||||||||||||||||||||
| 5 | 25 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 25 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 25 | our $VERSION = '2.20261029'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 8 | 25 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 25 | ▶ | use Mail::AuthenticationResults::Header; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 25 | ▶ | use Mail::AuthenticationResults::Header::AuthServID; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 25 | ▶ | use Mail::AuthenticationResults::Header::Comment; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 25 | ▶ | use Mail::AuthenticationResults::Header::Entry; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 25 | ▶ | use Mail::AuthenticationResults::Header::SubEntry; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 25 | ▶ | use Mail::AuthenticationResults::Header::Version; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 25 | ▶ | use Mail::AuthenticationResults::Token::Assignment; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 25 | ▶ | use Mail::AuthenticationResults::Token::Comment; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 25 | ▶ | use Mail::AuthenticationResults::Token::QuotedString; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 25 | ▶ | use Mail::AuthenticationResults::Token::Separator; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 25 | ▶ | use Mail::AuthenticationResults::Token::String; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 25 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 64 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 64 | my ( $class, $auth_header ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 64 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 64 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 64 | ▶ | if ( $auth_header ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 12 | $self->parse( $auth_header ); | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 64 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 62 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 62 | my ( $self, $header ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 62 | $self->tokenise( $header ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 57 | $self->_parse_authservid(); | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 50 | ▶ | while ( @{ $self->{ 'tokenised' } } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 2114 | $self->_parse_entry(); | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 46 | return $self->parsed(); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | sub from_authentication_results_json { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_authentication_results_json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | my ( $self, $json ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | my $j = JSON->new(); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | my $hashref = $j->decode( $json ); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | return $self->_from_hashref( $hashref ); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 24 | ▶ | sub _from_hashref { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_from_hashref: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 24 | my ( $self, $hashref ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 24 | my $type = $hashref->{'type'}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 24 | ▶ | my $object | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | = $type eq 'header' ? Mail::AuthenticationResults::Header->new() | ||||||||||||||||||||||||||||||||||||||||||
| 66 | : $type eq 'authservid' ? Mail::AuthenticationResults::Header::AuthServID->new() | ||||||||||||||||||||||||||||||||||||||||||
| 67 | : $type eq 'entry' ? Mail::AuthenticationResults::Header::Entry->new() | ||||||||||||||||||||||||||||||||||||||||||
| 68 | : $type eq 'subentry' ? Mail::AuthenticationResults::Header::SubEntry->new() | ||||||||||||||||||||||||||||||||||||||||||
| 69 | : $type eq 'comment' ? Mail::AuthenticationResults::Header::Comment->new() | ||||||||||||||||||||||||||||||||||||||||||
| 70 | : croak "unknown type $type"; | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 24 | ▶ | if ( $type eq 'header' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | my $authserv_id = $self->_from_hashref( $hashref->{ 'authserv_id' } ); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | $object->set_value( $authserv_id ); | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 23 | ▶ | $object->set_key( $hashref->{'key'} ) if exists $hashref->{'key'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 23 | ▶ | $object->safe_set_value( $hashref->{'value'} ) if exists $hashref->{'value'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 24 | ▶ | if ( exists $hashref->{'children'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 18 | for my $child ( @{ $hashref->{'children'} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 83 | 22 | my $child_object = $self->_from_hashref( $child ); | |||||||||||||||||||||||||||||||||||||||||
| 84 | 22 | $object->add_child( $child_object ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 24 | return $object; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 63 | ▶ | sub tokenise { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tokenise: called CC=18 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 63 | my ( $self, $header ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 63 | my @tokenised; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 63 | $header =~ s/\n/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 63 | $header =~ s/\r/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 63 | $header =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | # Remove Header part if present | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 63 | ▶ | if ( $header =~ /^Authentication-Results:/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 15 | $header =~ s/^Authentication-Results://i; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 63 | my $args = {}; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 63 | ▶ | while ( length($header) > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 53250 | my $token; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 53250 | $header =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 53250 | ▶ | my $last_non_comment_type = exists( $args->{ 'last_non_comment_type' } ) ? $args->{ 'last_non_comment_type' }->is() : 'none'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 53250 | ▶ | if ( length( $header ) == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | elsif ( $header =~ /^\(/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 2739 | $token = Mail::AuthenticationResults::Token::Comment->new( $header, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | elsif ( $header =~ /^;/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 4132 | $token = Mail::AuthenticationResults::Token::Separator->new( $header, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 4132 | $args->{ 'last_non_comment_type' } = $token; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | elsif ( $header =~ /^"/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 38 | $token = Mail::AuthenticationResults::Token::QuotedString->new( $header, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 38 | $args->{ 'last_non_comment_type' } = $token; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | ▶ | elsif ( $last_non_comment_type ne 'assignment' && $header =~ /^\./ ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$last_non_comment_type ne "assignment" and $header =~ /^\./
MC/DC100%2/2
$last_non_comment_type ne "assignment" and $header =~ /^\./
$last_non_comment_type ne "assignment"
$header =~ /^\./
Truth table100%3/3
A and B
A= $last_non_comment_type ne "assignment"B= $header =~ /^\./
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 6749 | $token = Mail::AuthenticationResults::Token::Assignment->new( $header, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 6749 | $args->{ 'last_non_comment_type' } = $token; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | ▶ | elsif ( $last_non_comment_type eq 'assignment' && $header =~ /^\./ ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$last_non_comment_type eq "assignment" and $header =~ /^\./
MC/DC100%2/2
$last_non_comment_type eq "assignment" and $header =~ /^\./
$last_non_comment_type eq "assignment"
$header =~ /^\./
Truth table100%3/3
A and B
A= $last_non_comment_type eq "assignment"B= $header =~ /^\./
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | # a . after an assignment cannot be another assignment, likely an unquoted string. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 4 | $token = Mail::AuthenticationResults::Token::String->new( $header, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | $args->{ 'last_non_comment_type' } = $token; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | ▶ | elsif ( $last_non_comment_type ne 'assignment' && $header =~ /^\// ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$last_non_comment_type ne "assignment" and $header =~ m[^/]
MC/DC100%2/2
$last_non_comment_type ne "assignment" and $header =~ m[^/]
$last_non_comment_type ne "assignment"
$header =~ m[^/]
Truth table100%3/3
A and B
A= $last_non_comment_type ne "assignment"B= $header =~ m[^/]
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | $token = Mail::AuthenticationResults::Token::Assignment->new( $header, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 4 | $args->{ 'last_non_comment_type' } = $token; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | ▶ | elsif ( $last_non_comment_type eq 'assignment' && $header =~ /^\// ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$last_non_comment_type eq "assignment" and $header =~ m[^/]
MC/DC100%2/2
$last_non_comment_type eq "assignment" and $header =~ m[^/]
$last_non_comment_type eq "assignment"
$header =~ m[^/]
Truth table100%3/3
A and B
A= $last_non_comment_type eq "assignment"B= $header =~ m[^/]
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | # a / after an assignment cannot be another assignment, likely an unquoted string. | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | $token = Mail::AuthenticationResults::Token::String->new( $header, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | $args->{ 'last_non_comment_type' } = $token; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | elsif ( $header =~ /^=/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 10935 | $token = Mail::AuthenticationResults::Token::Assignment->new( $header, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 149 | 10935 | $args->{ 'last_non_comment_type' } = $token; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 28645 | $token = Mail::AuthenticationResults::Token::String->new( $header, $args ); | |||||||||||||||||||||||||||||||||||||||||
| 153 | 28645 | $args->{ 'last_non_comment_type' } = $token; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 53245 | $header = $token->remainder(); | |||||||||||||||||||||||||||||||||||||||||
| 157 | # Do not retain a copy of the remaining header in every token, | ||||||||||||||||||||||||||||||||||||||||||
| 158 | # doing so uses memory quadratic in the number of tokens. | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # remainder() will return undef for these tokens, this is | ||||||||||||||||||||||||||||||||||||||||||
| 160 | # documented in Mail::AuthenticationResults::Token. | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 53245 | delete $token->{ 'header' }; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 53245 | push @tokenised, $token; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 60 | ▶ | croak 'Nothing to parse' if ! @tokenised; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 58 | $self->{ 'tokenised' } = \@tokenised; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 58 | return; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 57 | ▶ | sub _parse_authservid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_authservid: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 57 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 57 | my $tokenised = $self->{ 'tokenised' }; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 57 | my $token; | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 57 | my $authserv_id = Mail::AuthenticationResults::Header::AuthServID->new(); | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | # Find the ServID | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 57 | ▶ | while ( @$tokenised ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 58 | $token = shift @$tokenised; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 58 | ▶ | if ( $token->is() eq 'string' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 56 | $authserv_id->set_value( $token->value() ); | |||||||||||||||||||||||||||||||||||||||||
| 184 | 56 | last; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | elsif ( $token->is() eq 'comment' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | $authserv_id->add_child( Mail::AuthenticationResults::Header::Comment->new()->set_value( $token->value() ) ); | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 190 | # assignment or separator, both are bogus | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | croak 'Invalid AuthServ-ID'; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 56 | my $expecting = 'key'; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 56 | my $key; | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | TOKEN: | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 56 | ▶ | while ( @$tokenised ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 70 | $token = shift @$tokenised; | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 70 | ▶ | if ( $token->is() eq 'assignment' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 7 | ▶ | if ( $expecting eq 'assignment' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 4 | ▶ | if ( $token->value() eq '=' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 2 | $expecting = 'value'; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 2 | croak 'unexpected token'; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 3 | croak 'not expecting an assignment'; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | elsif ( $token->is() eq 'comment' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 3 | $authserv_id->add_child( Mail::AuthenticationResults::Header::Comment->new()->set_value( $token->value() ) ); | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | elsif ( $token->is() eq 'separator' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 49 | last TOKEN; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 16 | ▶ | if ( $token->is() eq 'string' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 11 | ▶ | if ( $expecting eq 'key' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 9 | $key = $token; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 9 | $expecting = 'assignment'; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | elsif ( $expecting eq 'value' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | $authserv_id->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( $key->value() )->set_value( $token->value() ) ); | |||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | $expecting = 'key'; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | undef $key; | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | croak 'not expecting a string'; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 50 | ▶ | if ( $expecting ne 'key' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | ▶ | if ( $key->value() =~ /^[0-9]+$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | # Looks like a version | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | $authserv_id->add_child( Mail::AuthenticationResults::Header::Version->new()->set_value( $key->value() ) ); | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # Probably bogus, but who knows! | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | $authserv_id->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( $key->value() ) ); | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 50 | $self->{ 'header' } = Mail::AuthenticationResults::Header->new()->set_value( $authserv_id ); | |||||||||||||||||||||||||||||||||||||||||
| 249 | 50 | $self->{ 'tokenised' } = $tokenised; | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 50 | return; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 2114 | ▶ | sub _parse_entry { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_entry: called CC=22 SCAR=30.9
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 2114 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 2114 | my $tokenised = $self->{ 'tokenised' }; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 2114 | my $entry = Mail::AuthenticationResults::Header::Entry->new(); | |||||||||||||||||||||||||||||||||||||||||
| 259 | 2114 | my $working_on = $entry; | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 2114 | my $expecting = 'key'; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 2114 | my $is_subentry = 0; | |||||||||||||||||||||||||||||||||||||||||
| 263 | TOKEN: | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 2114 | ▶ | while ( @$tokenised ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 27078 | my $token = shift @$tokenised; | |||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 27078 | ▶ | if ( $token->is() eq 'assignment' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 9005 | ▶ | if ( $expecting eq 'assignment' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 9004 | ▶ | if ( $token->value() eq '=' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 5590 | $expecting = 'value'; | |||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | elsif ( $token->value() eq '.' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 3412 | $expecting = 'keymod'; | |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | elsif ( $token->value() eq '/' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 2 | $expecting = 'version'; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | croak 'not expecting an assignment'; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | elsif ( $token->is() eq 'comment' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 1402 | $working_on->add_child( Mail::AuthenticationResults::Header::Comment->new()->set_value( $token->value() ) ); | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | elsif ( $token->is() eq 'separator' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 2071 | last TOKEN; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 25006 | ▶ | if ( $token->is() eq 'string' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 14600 | ▶ | if ( $expecting eq 'key' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 5601 | ▶ | if ( ! $is_subentry ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 2114 | ▶ | if ( $token->value() eq 'none' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | # Special case the none | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 7 | $expecting = 'no_more_after_none'; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 2107 | $entry->set_key( $token->value() ); | |||||||||||||||||||||||||||||||||||||||||
| 298 | 2107 | $expecting = 'assignment'; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 3487 | $working_on = Mail::AuthenticationResults::Header::SubEntry->new()->set_key( $token->value() ); | |||||||||||||||||||||||||||||||||||||||||
| 303 | 3487 | $expecting = 'assignment'; | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | elsif ( $expecting eq 'keymod' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 3412 | $working_on->set_key( $working_on->key() . '.' . $token->value() ); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 3412 | $expecting = 'assignment'; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | elsif ( $expecting eq 'version' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | ▶ | if ( $token->value() =~ /^[0-9]+$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | # Looks like a version | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | $working_on->add_child( Mail::AuthenticationResults::Header::Version->new()->set_value( $token->value() ) ); | |||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | croak 'bad version token'; | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | $expecting = 'assignment'; | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | elsif ( $expecting eq 'value' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 5583 | ▶ | if ( ! $is_subentry ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 2100 | $entry->set_value( $token->value() ); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 2100 | $is_subentry = 1; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 3483 | $entry->add_child( $working_on->set_value( $token->value() ) ); | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 5583 | $expecting = 'key'; | |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 2 | croak 'not expecting a string'; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 2110 | ▶ | if ( $expecting eq 'no_more_after_none' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 5 | $self->{ 'tokenised' } = $tokenised; | |||||||||||||||||||||||||||||||||||||||||
| 339 | # We may have comment entries, if so add those to the header object | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 5 | foreach my $child ( @{ $entry->children() } ) { | |||||||||||||||||||||||||||||||||||||||||
| 341 | 2 | delete $child->{ 'parent' }; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | $self->{ 'header' }->add_child( $child ); | |||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 2105 | ▶ | if ( $expecting ne 'key' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 9 | ▶ | if ( $is_subentry ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 4 | $entry->add_child( $working_on ); | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 2105 | $self->{ 'header' }->add_child( $entry ); | |||||||||||||||||||||||||||||||||||||||||
| 354 | 2105 | $self->{ 'tokenised' } = $tokenised; | |||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 2105 | return; | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 58 | ▶ | sub parsed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parsed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 58 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 58 | return $self->{ 'header' }; | |||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 25 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | __END__ | ||||||||||||||||||||||||||||||||||||||||||