File Coverage

lib/Mail/AuthenticationResults/Token/Comment.pm
Criterion Covered Total %
statement 36 36 100.0
branch 10 10 100.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 54 54 100.0


line stmt bran cond sub pod time code
1             package Mail::AuthenticationResults::Token::Comment;
2             # ABSTRACT: Class for modelling AuthenticationResults Header parts detected as comments
3              
4             require 5.008;
5 31     31   669 use strict;
  31         55  
  31         1301  
6 31     31   206 use warnings;
  31         49  
  31         2161  
7             our $VERSION = '2.20260216'; # VERSION
8 31     31   173 use Carp;
  31         49  
  31         1957  
9              
10 31     31   157 use base 'Mail::AuthenticationResults::Token';
  31         49  
  31         13424  
11              
12              
13             sub is {
14 406     406 1 715 my ( $self ) = @_;
15 406         1406 return 'comment';
16             }
17              
18             sub parse {
19 77     77 1 214 my ($self) = @_;
20              
21 77         160 my $header = $self->{ 'header' };
22 77         171 my $value = q{};
23 77         132 my $depth = 0;
24              
25 77         168 my $first = substr( $header,0,1 );
26 77 100       266 if ( $first ne '(' ) {
27 1         24 croak 'Not a comment';
28             }
29              
30 76         231 while ( length $header > 0 ) {
31 1720         2713 my $first = substr( $header,0,1 );
32 1720         2709 $header = substr( $header,1 );
33 1720         2443 $value .= $first;
34 1720 100       4366 if ( $first eq '(' ) {
    100          
35 77         220 $depth++;
36             }
37             elsif ( $first eq ')' ) {
38 76         132 $depth--;
39 76 100       274 last if $depth == 0;
40             }
41             }
42              
43 76 100       264 if ( $depth != 0 ) {
44 1         18 croak 'Mismatched parens in comment';
45             }
46              
47 75         305 $value =~ s/^\(//;
48 75         459 $value =~ s/\)$//;
49              
50 75         297 $self->{ 'value' } = $value;
51 75         156 $self->{ 'header' } = $header;
52              
53 75         296 return;
54             }
55              
56             1;
57              
58             __END__