« lib/Mail/AuthenticationResults/Token/String.pm
↑ Summary
lib/Mail/AuthenticationResults/Header/Group.pm »
| 1 | package Mail::AuthenticationResults::Header::Comment; | ||||||||||
| 2 | # ABSTRACT: Class modelling Comment parts of the Authentication Results Header | ||||||||||
| 3 | |||||||||||
| 4 | 31 | require 5.008; | |||||||||
| 5 | 31 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 31 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 31 | our $VERSION = '2.20261029'; # VERSION | |||||||||
| 8 | 31 | ▶ | use Scalar::Util qw{ weaken }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 31 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 31 | ▶ | use base 'Mail::AuthenticationResults::Header::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | 360 | ▶ | sub _HAS_VALUE{ return 1; } | ||||||||
|
Subroutine
_HAS_VALUE: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 15 | ▶ | sub safe_set_value { | ||||||||
|
Subroutine
safe_set_value: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||
| 17 | 15 | my ( $self, $value ) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 15 | ▶ | $value = q{} if ! defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | |||||||||||
| 21 | 15 | $value =~ s/\t/ /g; | |||||||||
| 22 | 15 | $value =~ s/\n/ /g; | |||||||||
| 23 | 15 | $value =~ s/\r/ /g; | |||||||||
| 24 | |||||||||||
| 25 | 15 | my $remain = $value; | |||||||||
| 26 | 15 | my $depth = 0; | |||||||||
| 27 | 15 | my $nested_ok = 1; | |||||||||
| 28 | 15 | ▶ | while ( length $remain > 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 153 | my $first = substr( $remain,0,1 ); | |||||||||
| 30 | 153 | $remain = substr( $remain,1 ); | |||||||||
| 31 | 153 | ▶ | $depth++ if $first eq '('; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 153 | ▶ | $depth-- if $first eq ')'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 153 | ▶ | $nested_ok = 0 if $depth == -1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | } | ||||||||||
| 35 | 15 | ▶ | $nested_ok = 0 if $depth != 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | |||||||||||
| 37 | # Remove parens if nested comments would be broken by them. | ||||||||||
| 38 | 15 | ▶ | if ( ! $nested_ok ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 5 | $value =~ s/\(/ /g; | |||||||||
| 40 | 5 | $value =~ s/\)/ /g; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 15 | $value =~ s/^\s+//; | |||||||||
| 44 | 15 | $value =~ s/\s+$//; | |||||||||
| 45 | #$value =~ s/;/ /g; | ||||||||||
| 46 | |||||||||||
| 47 | 15 | $self->set_value( $value ); | |||||||||
| 48 | 15 | return $self; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 1428 | ▶ | sub set_value { | ||||||||
|
Subroutine
set_value: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||
| 52 | 1428 | my ( $self, $value ) = @_; | |||||||||
| 53 | |||||||||||
| 54 | 1428 | my $remain = $value; | |||||||||
| 55 | 1428 | my $depth = 0; | |||||||||
| 56 | 1428 | ▶ | while ( length $remain > 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 17712 | my $first = substr( $remain,0,1 ); | |||||||||
| 58 | 17712 | $remain = substr( $remain,1 ); | |||||||||
| 59 | 17712 | ▶ | $depth++ if $first eq '('; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 17712 | ▶ | $depth-- if $first eq ')'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 17712 | ▶ | croak 'Out of order parens in comment' if $depth == -1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | } | ||||||||||
| 63 | 1425 | ▶ | croak 'Mismatched parens in comment' if $depth != 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 1423 | ▶ | croak 'Invalid characters in value' if $value =~ /\n/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 1423 | ▶ | croak 'Invalid characters in value' if $value =~ /\r/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | |||||||||||
| 67 | 1423 | $self->{ 'value' } = $value; | |||||||||
| 68 | 1423 | return $self; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 91 | ▶ | sub build_string { | ||||||||
|
Subroutine
build_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 72 | 91 | my ( $self, $header ) = @_; | |||||||||
| 73 | 91 | $header->comment( '(' . $self->value() . ')' ); | |||||||||
| 74 | 91 | return; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 31 | 1; | |||||||||
| 78 | |||||||||||
| 79 | __END__ | ||||||||||