File Coverage

blib/lib/PGP/Finger/ResultSet.pm
Criterion Covered Total %
statement 3 26 11.5
branch 0 10 0.0
condition n/a
subroutine 1 3 33.3
pod 0 2 0.0
total 4 41 9.7


line stmt bran cond sub pod time code
1             package PGP::Finger::ResultSet;
2              
3 1     1   4 use Moose;
  1         1  
  1         6  
4              
5             # ABSTRACT: object to hold and merge Result objects
6             our $VERSION = '1.1'; # VERSION
7              
8             has 'results' => (
9             is => 'ro', isa => 'ArrayRef[PGP::Finger::Result]', lazy => 1,
10             traits => [ 'Array' ],
11             default => sub { [] },
12             handles => {
13             add_result => 'push',
14             count => 'count',
15             },
16             );
17              
18             sub merged_keys {
19 0     0 0   my $self = shift;
20 0           my %keys;
21              
22 0           foreach my $result ( @{$self->results} ) {
  0            
23 0           foreach my $key ( @{$result->keys} ) {
  0            
24 0           my $fp = $key->fingerprint;
25 0 0         if( defined $keys{$fp} ) {
26 0           $keys{$fp}->merge_key( $key );
27             } else {
28 0           $keys{$fp} = $key->clone;
29             }
30             }
31             }
32              
33 0           return( values %keys );
34             }
35              
36             sub as_string {
37 0     0 0   my ( $self, $type ) = @_;
38 0           $type = lc $type;
39 0           my @keys = $self->merged_keys;
40 0           my $result = '';
41              
42 0           foreach my $key ( @keys ) {
43 0 0         if( $type eq 'armored' ) {
    0          
    0          
    0          
44 0           $result .= $key->armored;
45             } elsif ( $type eq 'binary' ){
46 0           $result .= $key->data;
47             } elsif ( $type eq 'generic' ){
48 0           $result .= $key->dns_record_generic;
49             } elsif ( $type eq 'rfc' ){
50 0           $result .= $key->dns_record_rfc;
51             } else {
52 0           die('invalid output format: '.$type);
53             }
54             }
55              
56 0           return $result;
57             }
58              
59             1;
60              
61             __END__
62              
63             =pod
64              
65             =encoding UTF-8
66              
67             =head1 NAME
68              
69             PGP::Finger::ResultSet - object to hold and merge Result objects
70              
71             =head1 VERSION
72              
73             version 1.1
74              
75             =head1 AUTHOR
76              
77             Markus Benning <ich@markusbenning.de>
78              
79             =head1 COPYRIGHT AND LICENSE
80              
81             This software is Copyright (c) 2015 by Markus Benning.
82              
83             This is free software, licensed under:
84              
85             The GNU General Public License, Version 2 or later
86              
87             =cut