| 1 | package PGP::Finger::App; | ||
| 2 | |||
| 3 | use Moose; | ||
| 4 | |||
| 5 | our $VERSION = '1.0'; # VERSION | ||
| 6 | # ABSTRACT: commandline interface to PGP::Finger | ||
| 7 | |||
| 8 | extends 'PGP::Finger'; | ||
| 9 | with 'MooseX::Getopt'; | ||
| 10 | |||
| 11 | use PGP::Finger::DNS; | ||
| 12 | use PGP::Finger::Keyserver; | ||
| 13 | use PGP::Finger::GPG; | ||
| 14 | |||
| 15 | has '+sources' => ( | ||
| 16 | traits => [ 'NoGetopt' ], | ||
| 17 | default => sub { | ||
| 18 | my $self = shift; | ||
| 19 | my @srcs; | ||
| 20 | foreach my $q ( @{$self->_query} ) { | ||
| 21 | my $src; | ||
| 22 | $q = lc($q); | ||
| 23 | if( $q eq 'dns' ) { | ||
| 24 | $src = PGP::Finger::DNS->new(); | ||
| 25 | } elsif( $q eq 'keyserver' ) { | ||
| 26 | $src = PGP::Finger::Keyserver->new(); | ||
| 27 | } elsif( $q eq 'gpg' ) { | ||
| 28 | $src = PGP::Finger::GPG->new(); | ||
| 29 | } else { | ||
| 30 | die('unknown query type: '.$q); | ||
| 31 | } | ||
| 32 | push( @srcs, $src ); | ||
| 33 | } | ||
| 34 | return( \@srcs ); | ||
| 35 | }, | ||
| 36 | ); | ||
| 37 | |||
| 38 | has 'query' => ( is => 'ro', isa => 'Str', default => 'dns,keyserver', | ||
| 39 | traits => ['Getopt'], | ||
| 40 | cmd_aliases => 'q', | ||
| 41 | documentation => 'sources to query (default: dns,keyserver)', | ||
| 42 | ); | ||
| 43 | |||
| 44 | has '_query' => ( is => 'ro', isa => 'ArrayRef[Str]', lazy => 1, | ||
| 45 | default => sub { | ||
| 46 | my $self = shift; | ||
| 47 | return [ split(/\s*,\s*/, $self->query) ]; | ||
| 48 | }, | ||
| 49 | ); | ||
| 50 | |||
| 51 | has 'output' => ( is => 'ro', isa => 'Str', default => 'armored', | ||
| 52 | traits => ['Getopt'], | ||
| 53 | cmd_aliases => 'o', | ||
| 54 | documentation => 'output format: armored,rfc or generic (default: armored)', | ||
| 55 | ); | ||
| 56 | |||
| 57 | sub _usage_format { | ||
| 58 | return "usage: %c %o <uid> <more uids ...>"; | ||
| 59 | } | ||
| 60 | |||
| 61 | sub run { | ||
| 62 | my $self = shift; | ||
| 63 | my @uids = @{$self->extra_argv}; | ||
| 64 | |||
| 65 | if( ! @uids ) { | ||
| 66 | print $self->usage; | ||
| 67 | exit 1; | ||
| 68 | } | ||
| 69 | |||
| 70 | foreach my $uid ( @uids ) { | ||
| 71 | my $resultset = $self->fetch( $uid ); | ||
| 72 | print $resultset->as_string( $self->output ); | ||
| 73 | } | ||
| 74 | |||
| 75 | return; | ||
| 76 | } | ||
| 77 | |||
| 78 | 1; | ||
| 79 | |||
| 80 | __END__ | ||
| 81 | |||
| 82 | =pod | ||
| 83 | |||
| 84 | =encoding UTF-8 | ||
| 85 | |||
| 86 | =head1 NAME | ||
| 87 | |||
| 88 | PGP::Finger::App - commandline interface to PGP::Finger | ||
| 89 | |||
| 90 | =head1 VERSION | ||
| 91 | |||
| 92 | version 1.0 | ||
| 93 | |||
| 94 | =head1 AUTHOR | ||
| 95 | |||
| 96 | Markus Benning <ich@markusbenning.de> | ||
| 97 | |||
| 98 | =head1 COPYRIGHT AND LICENSE | ||
| 99 | |||
| 100 | This software is Copyright (c) 2015 by Markus Benning. | ||
| 101 | |||
| 102 | This is free software, licensed under: | ||
| 103 | |||
| 104 | The GNU General Public License, Version 2 or later | ||
| 105 | |||
| 106 | =cut |