File Coverage

blib/lib/GnuPG/Handles.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
path n/a
condition n/a
subroutine 6 6 100.0
pod 1 2 50.0
total 23 24 95.8


line stmt bran path cond sub pod time code
1               # Handles.pm
2               # - interface to the handles used by GnuPG::Interface
3               #
4               # Copyright (C) 2000 Frank J. Tobin <ftobin@cpan.org>
5               #
6               # This module is free software; you can redistribute it and/or modify it
7               # under the same terms as Perl itself.
8               #
9               # This program is distributed in the hope that it will be useful,
10               # but WITHOUT ANY WARRANTY; without even the implied warranty of
11               # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12               #
13               # $Id: Handles.pm,v 1.8 2001/12/09 02:24:10 ftobin Exp $
14               #
15                
16               package GnuPG::Handles;
17 71       71   603 use Moo;
  71           158  
  71           591  
18 71       71   27896 use MooX::late;
  71           160  
  71           541  
19               with qw(GnuPG::HashInit);
20                
21 71           21235 use constant HANDLES => qw(
22               stdin
23               stdout
24               stderr
25               status
26               logger
27               passphrase
28               command
29 71       71   21861 );
  71           226  
30                
31               has "$_" => (
32               isa => 'Any',
33               is => 'rw',
34               clearer => 'clear_' . $_,
35               ) for HANDLES;
36                
37               has _options => (
38               isa => 'HashRef',
39               is => 'rw',
40               lazy_build => 1,
41               );
42                
43               sub options {
44 650       650 1 44694 my $self = shift;
45 650           1256 my $key = shift;
46                
47 650           11311 return $self->_options->{$key};
48               }
49                
50 232       232   7734 sub _build__options { {} }
51                
52               sub BUILD {
53 232       232 0 26494241 my ( $self, $args ) = @_;
54                
55               # This is done for the user's convenience so that they don't
56               # have to worry about undefined hashrefs
57 232           10214 $self->_options->{$_} = {} for HANDLES;
58 232           40357 $self->hash_init(%$args);
59               }
60                
61               1;
62                
63               =head1 NAME
64                
65               GnuPG::Handles - GnuPG handles bundle
66                
67               =head1 SYNOPSIS
68                
69               use IO::Handle;
70               my ( $stdin, $stdout, $stderr,
71               $status_fh, $logger_fh, $passphrase_fh,
72               )
73               = ( IO::Handle->new(), IO::Handle->new(), IO::Handle->new(),
74               IO::Handle->new(), IO::Handle->new(), IO::Handle->new(),
75               );
76                
77               my $handles = GnuPG::Handles->new
78               ( stdin => $stdin,
79               stdout => $stdout,
80               stderr => $stderr,
81               status => $status_fh,
82               logger => $logger_fh,
83               passphrase => $passphrase_fh,
84               );
85                
86               =head1 DESCRIPTION
87                
88               GnuPG::Handles objects are generally instantiated
89               to be used in conjunction with methods of objects
90               of the class GnuPG::Interface. GnuPG::Handles objects
91               represent a collection of handles that are used to
92               communicate with GnuPG.
93                
94               =head1 OBJECT METHODS
95                
96               =head2 Initialization Methods
97                
98               =over 4
99                
100               =item new( I<%initialization_args> )
101                
102               This methods creates a new object. The optional arguments are
103               initialization of data members.
104                
105               =item hash_init( I<%args> ).
106                
107                
108               =back
109                
110               =head1 OBJECT DATA MEMBERS
111                
112               =over 4
113                
114               =item stdin
115                
116               This handle is connected to the standard input of a GnuPG process.
117                
118               =item stdout
119                
120               This handle is connected to the standard output of a GnuPG process.
121                
122               =item stderr
123                
124               This handle is connected to the standard error of a GnuPG process.
125                
126               =item status
127                
128               This handle is connected to the status output handle of a GnuPG process.
129                
130               =item logger
131                
132               This handle is connected to the logger output handle of a GnuPG process.
133                
134               =item passphrase
135                
136               This handle is connected to the passphrase input handle of a GnuPG process.
137                
138               =item command
139                
140               This handle is connected to the command input handle of a GnuPG process.
141                
142               =item options
143                
144               This is a hash of hashrefs of settings pertaining to the handles
145               in this object. The outer-level hash is keyed by the names of the
146               handle the setting is for, while the inner is keyed by the setting
147               being referenced. For example, to set the setting C<direct> to true
148               for the filehandle C<stdin>, the following code will do:
149                
150               # assuming $handles is an already-created
151               # GnuPG::Handles object, this sets all
152               # options for the filehandle stdin in one blow,
153               # clearing out all others
154               $handles->options( 'stdin', { direct => 1 } );
155                
156               # this is useful to just make one change
157               # to the set of options for a handle
158               $handles->options( 'stdin' )->{direct} = 1;
159                
160               # and to get the setting...
161               $setting = $handles->options( 'stdin' )->{direct};
162                
163               # and to clear the settings for stdin
164               $handles->options( 'stdin', {} );
165                
166               The currently-used settings are as follows:
167                
168               =over 4
169                
170               =item direct
171                
172               If the setting C<direct> is true for a handle, the GnuPG
173               process spawned will access the handle directly. This is useful for
174               having the GnuPG process read or write directly to or from
175               an already-opened file.
176                
177               =back
178                
179               =back
180                
181               =head1 SEE ALSO
182                
183               L<GnuPG::Interface>,
184                
185               =cut