« lib/Mail/AuthenticationResults/Token/String.pm
↑ Summary
blib/lib/Mail/AuthenticationResults/Header.pm »
| 1 | package Mail::AuthenticationResults::Token::Comment; | ||
| 2 | # ABSTRACT: Class for modelling AuthenticationResults Header parts detected as comments | ||
| 3 | |||
| 4 | require 5.008; | ||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | our $VERSION = '2.20260216'; # VERSION | ||
| 8 | use Carp; | ||
| 9 | |||
| 10 | use base 'Mail::AuthenticationResults::Token'; | ||
| 11 | |||
| 12 | |||
| 13 | sub is { | ||
| 14 | my ( $self ) = @_; | ||
| 15 | return 'comment'; | ||
| 16 | } | ||
| 17 | |||
| 18 | sub parse { | ||
| 19 | my ($self) = @_; | ||
| 20 | |||
| 21 | my $header = $self->{ 'header' }; | ||
| 22 | my $value = q{}; | ||
| 23 | my $depth = 0; | ||
| 24 | |||
| 25 | my $first = substr( $header,0,1 ); | ||
| 26 | if ( $first ne '(' ) { | ||
| 27 | croak 'Not a comment'; | ||
| 28 | } | ||
| 29 | |||
| 30 | while ( length $header > 0 ) { | ||
| 31 | my $first = substr( $header,0,1 ); | ||
| 32 | $header = substr( $header,1 ); | ||
| 33 | $value .= $first; | ||
| 34 | if ( $first eq '(' ) { | ||
| 35 | $depth++; | ||
| 36 | } | ||
| 37 | elsif ( $first eq ')' ) { | ||
| 38 | $depth--; | ||
| 39 | last if $depth == 0; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | if ( $depth != 0 ) { | ||
| 44 | croak 'Mismatched parens in comment'; | ||
| 45 | } | ||
| 46 | |||
| 47 | $value =~ s/^\(//; | ||
| 48 | $value =~ s/\)$//; | ||
| 49 | |||
| 50 | $self->{ 'value' } = $value; | ||
| 51 | $self->{ 'header' } = $header; | ||
| 52 | |||
| 53 | return; | ||
| 54 | } | ||
| 55 | |||
| 56 | 1; | ||
| 57 | |||
| 58 | __END__ |