File Coverage

blib/lib/Protocol/OTR/Account.pm
Criterion Covered Total %
statement 8 10 80.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 12 14 85.7


line stmt bran cond sub pod time code
1             # ABSTRACT: Off-the-Record Account (private key)
2             package Protocol::OTR::Account;
3             BEGIN {
4 4     4   135 $Protocol::OTR::Account::AUTHORITY = 'cpan:AJGB';
5             }
6             $Protocol::OTR::Account::VERSION = '0.04';
7 4     4   18 use strict;
  4         7  
  4         129  
8 4     4   18 use warnings;
  4         6  
  4         126  
9 4     4   1608 use Protocol::OTR::Contact ();
  0            
  0            
10             use Params::Validate qw(validate validate_pos SCALAR BOOLEAN);
11              
12             sub _new {
13             my ($class, $otr, $args, $find_only) = @_;
14              
15             my $m = $find_only ? "_find_account" : "_account";
16              
17             $args->{fingerprint} = $otr->$m( $args->{name}, $args->{protocol} );
18              
19             return unless $args->{fingerprint};
20              
21             my $self = bless $args, $class;
22             $self->{otr} = $otr;
23              
24             return $self;
25             }
26              
27             sub ctx {
28             return $_[0]->{otr};
29             }
30              
31             sub name {
32             return $_[0]->{name};
33             }
34              
35             sub protocol {
36             return $_[0]->{protocol};
37             }
38              
39             sub fingerprint {
40             return $_[0]->{fingerprint};
41             }
42              
43             sub contact {
44             my $self = shift;
45              
46             my ($name, $fingerprint, $is_verified) = validate_pos(
47             @_,
48             {
49             type => SCALAR,
50             },
51             {
52             type => SCALAR,
53             optional => 1,
54             },
55             {
56             type => BOOLEAN,
57             optional => 1,
58             }
59             );
60              
61             return Protocol::OTR::Contact->_new(
62             $self,
63             {
64             name => $name,
65             fingerprint => $fingerprint,
66             is_verified => $is_verified,
67             }
68             );
69             }
70              
71             sub contacts {
72             my ($self) = @_;
73              
74             return map {
75             Protocol::OTR::Contact->_new($self, { name => $_ } )
76             } @{ $self->_contacts() }
77             }
78              
79             1;
80              
81             __END__