File Coverage

blib/lib/PGP/Finger/File.pm
Criterion Covered Total %
statement 15 38 39.4
branch 0 8 0.0
condition n/a
subroutine 5 7 71.4
pod 0 1 0.0
total 20 54 37.0


line stmt bran cond sub pod time code
1             package PGP::Finger::File;
2              
3 1     1   1928 use Moose;
  1         2  
  1         15  
4              
5             extends 'PGP::Finger::Source';
6              
7             # ABSTRACT: gpgfinger source for local file input
8             our $VERSION = '1.1'; # VERSION
9              
10 1     1   4916 use PGP::Finger::Result;
  1         2  
  1         7  
11 1     1   15 use PGP::Finger::Key;
  1         1  
  1         8  
12              
13 1     1   515 use IO::File;
  1         1504  
  1         99  
14 1     1   5 use IO::Handle;
  1         1  
  1         249  
15              
16             has 'input' => ( is => 'ro', isa => 'Str', required => 1 );
17              
18             has 'format' => ( is => 'ro', isa => 'Str', default => 'armored' );
19              
20             has '_data' => ( is => 'ro', lazy_build => 1 );
21              
22             sub _build__data {
23 0     0     my $self = shift;
24 0           my $fh;
25             my $buf;
26 0           my $data = '';
27              
28 0 0         if( $self->input eq '-' ) {
29 0           $fh = IO::Handle->new_from_fd(fileno(STDIN),'r');
30             } else {
31 0           $fh = IO::File->new($self->input,'r');
32             }
33 0 0         if( ! defined $fh ) {
34 0           die('unable to open '.$self->input.': '.$!);
35             }
36              
37 0           while( $fh->read( $buf, 1024 ) ) {
38 0           $data .= $buf;
39             }
40              
41 0           $fh->close;
42              
43 0           return $data;
44             }
45              
46             sub fetch {
47 0     0 0   my ( $self, $addr ) = @_;
48 0           my $result = PGP::Finger::Result->new;
49 0           my $key;
50              
51 0 0         if( $self->format eq 'armored' ) {
    0          
52 0           $key = PGP::Finger::Key->new_armored(
53             mail => $addr,
54             data => $self->_data,
55             );
56             } elsif ( $self->format eq 'binary' ) {
57 0           $key = PGP::Finger::Key->new(
58             mail => $addr,
59             data => $self->_data,
60             );
61             } else {
62 0           die('unknown input format: '.$self->format);
63             }
64 0           $key->set_attr( source => 'local file input' );
65 0           $key->set_attr( input => $self->input );
66              
67 0           $result->add_key( $key );
68 0           return $result;
69             }
70              
71             1;
72              
73             __END__
74              
75             =pod
76              
77             =encoding UTF-8
78              
79             =head1 NAME
80              
81             PGP::Finger::File - gpgfinger source for local file input
82              
83             =head1 VERSION
84              
85             version 1.1
86              
87             =head1 AUTHOR
88              
89             Markus Benning <ich@markusbenning.de>
90              
91             =head1 COPYRIGHT AND LICENSE
92              
93             This software is Copyright (c) 2015 by Markus Benning.
94              
95             This is free software, licensed under:
96              
97             The GNU General Public License, Version 2 or later
98              
99             =cut