File Coverage

blib/lib/Protocol/OTR/Contact.pm
Criterion Covered Total %
statement 17 19 89.4
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 24 26 92.3


line stmt bran cond sub pod time code
1             # ABSTRACT: Off-the-Record Contact
2             package Protocol::OTR::Contact;
3             BEGIN {
4 4     4   130 $Protocol::OTR::Contact::AUTHORITY = 'cpan:AJGB';
5             }
6             $Protocol::OTR::Contact::VERSION = '0.04';
7 4     4   18 use strict;
  4         7  
  4         101  
8 4     4   17 use warnings;
  4         5  
  4         121  
9 4     4   15 use Protocol::OTR ();
  4         6  
  4         57  
10 4     4   1590 use Protocol::OTR::Fingerprint ();
  4         675  
  4         76  
11 4     4   3235 use Protocol::OTR::Channel ();
  4         7  
  4         83  
12 4     4   4512 use Params::Validate qw(validate CODEREF);
  0            
  0            
13              
14             sub _new {
15             my ($class, $act, $args) = @_;
16              
17             $act->_contact( @$args{qw( name fingerprint is_verified )} );
18              
19             my $self = bless $args, $class;
20             $self->{act} = $act;
21              
22             return $self;
23             }
24              
25             sub account {
26             return $_[0]->{act};
27             }
28              
29             sub name {
30             return $_[0]->{name};
31             }
32              
33             sub fingerprints {
34             my ($self) = @_;
35              
36             return map {
37             Protocol::OTR::Fingerprint->_new($self, $_)
38             } @{ $self->_fingerprints() }
39             }
40              
41             sub active_fingerprint {
42             my ($self) = @_;
43              
44             if ( my $fprint = $self->_active_fingerprint() ) {
45             return Protocol::OTR::Fingerprint->_new($self, $fprint);
46             };
47              
48             return;
49             }
50              
51             sub channel {
52             my $self = shift;
53              
54             my %args = validate(
55             @_,
56             {
57             policy => {
58             optional => 1,
59             default => Protocol::OTR::POLICY_OPPORTUNISTIC(),
60             },
61             max_message_size => {
62             optional => 1,
63             default => 0,
64             },
65             on_read => {
66             type => CODEREF,
67             },
68             on_write => {
69             type => CODEREF,
70             },
71             on_gone_secure => {
72             optional => 1,
73             type => CODEREF,
74             },
75             on_gone_insecure => {
76             optional => 1,
77             type => CODEREF,
78             },
79             on_still_secure => {
80             optional => 1,
81             type => CODEREF,
82             },
83             on_unverified_fingerprint => {
84             optional => 1,
85             type => CODEREF,
86             },
87             on_symkey => {
88             optional => 1,
89             type => CODEREF,
90             },
91             on_timer => {
92             optional => 1,
93             type => CODEREF,
94             },
95             on_smp => {
96             optional => 1,
97             type => CODEREF,
98             },
99             on_error => {
100             optional => 1,
101             type => CODEREF,
102             },
103             on_event => {
104             optional => 1,
105             type => CODEREF,
106             },
107             on_smp_event => {
108             optional => 1,
109             type => CODEREF,
110             },
111             on_before_encrypt => {
112             optional => 1,
113             type => CODEREF,
114             },
115             on_after_decrypt => {
116             optional => 1,
117             type => CODEREF,
118             },
119             on_is_contact_logged_in => {
120             optional => 1,
121             type => CODEREF,
122             },
123             }
124             );
125              
126             return Protocol::OTR::Channel->_new($self, \%args);
127             }
128              
129             1;
130              
131             __END__