File Coverage

lib/Mail/TempAddress/Address.pm
Criterion Covered Total %
statement 27 27 100.0
branch 4 4 100.0
condition n/a
subroutine 9 9 100.0
pod 5 6 83.3
total 45 46 97.8


line stmt bran cond sub pod time code
1             package Mail::TempAddress::Address;
2              
3 2     2   965 use strict;
  2         5  
  2         94  
4              
5 2     2   985 use Mail::Action::Address;
  2         2949  
  2         75  
6             use Class::Roles
7 2         12 does => 'address_expires',
8             does => 'address_named',
9 2     2   28 does => 'address_described';
  2         4  
10              
11             sub new
12             {
13 19     19 1 82057 my $class = shift;
14 19         199 bless {
15             expires => 0,
16             @_,
17             }, $class;
18             }
19              
20             sub owner
21             {
22 5     5 1 14 my $self = shift;
23 5         25 return $self->{owner};
24             }
25              
26             sub attributes
27             {
28 4     4 1 2103 { expires => 1, description => 1 }
29             }
30              
31             sub add_sender
32             {
33 9     9 1 2899 my ($self, $sender) = @_;
34              
35 9         30 my $key = $self->get_key( $sender );
36 9         33 $self->{senders}{ $key } = $sender;
37              
38 9         34 return $key;
39             }
40              
41             sub get_key
42             {
43 9     9 0 16 my ($self, $sender) = @_;
44 9 100       36 return $self->{keys}{ $sender } if exists $self->{keys}{ $sender };
45              
46 8         52 my $key = sprintf '%x', reverse scalar time();
47              
48             do
49 8         10 {
50 8         184 $key = sprintf '%x', reverse( time() + rand( $$ ) );
51             } while ( exists $self->{keys}{ $key } );
52              
53 8         32 return $self->{keys}{ $sender } = $key;
54             }
55              
56             sub get_sender
57             {
58 4     4 1 2282 my ($self, $key) = @_;
59              
60 4 100       24 return unless exists $self->{senders}{ $key };
61 3         37 return $self->{senders}{ $key };
62             }
63              
64             1;
65              
66             __END__