| blib/lib/MIME/Disclaimer.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % | 
| statement | 29 | 36 | 80.5 | 
| branch | 0 | 2 | 0.0 | 
| condition | n/a | ||
| subroutine | 10 | 12 | 83.3 | 
| pod | 1 | 1 | 100.0 | 
| total | 40 | 51 | 78.4 | 
| line | stmt | bran | cond | sub | pod | time | code | 
|---|---|---|---|---|---|---|---|
| 1 | package MIME::Disclaimer; | ||||||
| 2 | |||||||
| 3 | 1 | 1 | 75392 | use 5.014; | |||
| 1 | 12 | ||||||
| 4 | 1 | 1 | 4 | use strict; | |||
| 1 | 1 | ||||||
| 1 | 31 | ||||||
| 5 | 1 | 1 | 4 | use warnings; | |||
| 1 | 2 | ||||||
| 1 | 28 | ||||||
| 6 | 1 | 1 | 359 | use parent -norequire, 'MIME::Signature'; | |||
| 1 | 250 | ||||||
| 1 | 5 | ||||||
| 7 | |||||||
| 8 | 1 | 1 | 390 | use MIME::Signature qw(_decoded_body _replace_body); | |||
| 1 | 3 | ||||||
| 1 | 62 | ||||||
| 9 | 1 | 1 | 447 | use Class::Method::Modifiers; | |||
| 1 | 1368 | ||||||
| 1 | 60 | ||||||
| 10 | |||||||
| 11 | our $VERSION = '0.17'; | ||||||
| 12 | |||||||
| 13 | 1 | 1 | 6 | use constant EMPTY => ''; | |||
| 1 | 2 | ||||||
| 1 | 121 | ||||||
| 14 | 1 | 1 | 5 | use constant NEWLINE => "\n"; | |||
| 1 | 2 | ||||||
| 1 | 45 | ||||||
| 15 | 1 | 1 | 5 | use constant LINEBREAK       => ' '; | |||
| 1 | 2 | ||||||
| 1 | 35 | ||||||
| 16 | 1 | 1 | 5 | use constant HORIZONTAL_RULE => ' '; | |||
| 1 | 2 | ||||||
| 1 | 436 | ||||||
| 17 | |||||||
| 18 | around 'new' => sub { | ||||||
| 19 | my $orig = shift; | ||||||
| 20 | my $class = shift; | ||||||
| 21 | my %args = @_; | ||||||
| 22 | my $self = $class->$orig(%args); | ||||||
| 23 | |||||||
| 24 | for (qw(plain_delimiter html_delimiter enriched_delimiter)) { | ||||||
| 25 | unless (exists $args{$_}) { | ||||||
| 26 | my $delimiter = ($_ eq 'html_delimiter') ? LINEBREAK . HORIZONTAL_RULE : NEWLINE; | ||||||
| 27 | $self->$_($delimiter); | ||||||
| 28 | } | ||||||
| 29 | } | ||||||
| 30 | |||||||
| 31 | return $self; | ||||||
| 32 | }; | ||||||
| 33 | |||||||
| 34 | around 'handler_text_enriched' => sub { | ||||||
| 35 | my $orig = shift; | ||||||
| 36 | my $self = shift; | ||||||
| 37 | my $entity = shift; | ||||||
| 38 | |||||||
| 39 | $orig->($self, $entity); | ||||||
| 40 | |||||||
| 41 | _replace_body($entity, $self->_disclaimer('enriched') . _decoded_body($entity)); | ||||||
| 42 | }; | ||||||
| 43 | |||||||
| 44 | around 'handler_text_html' => sub { | ||||||
| 45 | my $orig = shift; | ||||||
| 46 | my $self = shift; | ||||||
| 47 | my $entity = shift; | ||||||
| 48 | |||||||
| 49 | $orig->($self, $entity); | ||||||
| 50 | |||||||
| 51 | my $body = _decoded_body($entity); | ||||||
| 52 | require HTML::Parser; | ||||||
| 53 | my $new_body; | ||||||
| 54 | my $parser = HTML::Parser->new( | ||||||
| 55 | start_h => [ | ||||||
| 56 | sub { | ||||||
| 57 | my ($text, $tagname) = @_; | ||||||
| 58 | $new_body .= $text; | ||||||
| 59 | $new_body .= $self->_disclaimer('html') if lc $tagname eq 'body'; | ||||||
| 60 | }, | ||||||
| 61 | 'text,tagname' | ||||||
| 62 | ], | ||||||
| 63 | default_h => [sub {$new_body .= shift}, 'text'], | ||||||
| 64 | ); | ||||||
| 65 | $parser->parse($body); | ||||||
| 66 | _replace_body($entity, $new_body); | ||||||
| 67 | }; | ||||||
| 68 | |||||||
| 69 | around 'handler_text_plain' => sub { | ||||||
| 70 | my $orig = shift; | ||||||
| 71 | my $self = shift; | ||||||
| 72 | my $entity = shift; | ||||||
| 73 | |||||||
| 74 | $orig->($self, $entity); | ||||||
| 75 | |||||||
| 76 | _replace_body($entity, $self->_disclaimer('plain') . _decoded_body($entity)); | ||||||
| 77 | }; | ||||||
| 78 | |||||||
| 79 | sub _disclaimer { | ||||||
| 80 | 0 | 0 | my ($self, $type) = @_; | ||||
| 81 | |||||||
| 82 | 0 | 0 | defined(my $signature = $self->$type) or return; | ||||
| 83 | 0 | my $delimiter_method = $type . '_delimiter'; | |||||
| 84 | 0 | my $delimiter = $self->$delimiter_method; | |||||
| 85 | |||||||
| 86 | 0 | return join(EMPTY, ($delimiter, $signature, $delimiter)); | |||||
| 87 | } | ||||||
| 88 | |||||||
| 89 | sub add { | ||||||
| 90 | 0 | 0 | 1 | my $self = shift; | |||
| 91 | 0 | return $self->append(@_); | |||||
| 92 | } | ||||||
| 93 | |||||||
| 94 | 1; | ||||||
| 95 | |||||||
| 96 | __END__ |