home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / perl5 / GnuPG / Handles.pm < prev    next >
Encoding:
Perl POD Document  |  2009-07-13  |  4.1 KB  |  187 lines

  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. use Any::Moose;
  18. with qw(GnuPG::HashInit);
  19.  
  20. use constant HANDLES => qw(
  21.     stdin
  22.     stdout
  23.     stderr
  24.     status
  25.     logger
  26.     passphrase
  27.     command
  28. );
  29.  
  30. has "$_" => (
  31.     isa     => 'Any',
  32.     is      => 'rw',
  33.     clearer => 'clear_' . $_,
  34. ) for HANDLES;
  35.  
  36. has _options => (
  37.     isa        => 'HashRef',
  38.     is         => 'rw',
  39.     lazy_build => 1,
  40. );
  41.  
  42. sub options {
  43.     my $self = shift;
  44.     my $key = shift;
  45.  
  46.     return $self->_options->{$key};
  47. }
  48.  
  49. sub _build__options { {} }
  50.  
  51. sub BUILD {
  52.     my ( $self, $args ) = @_;
  53.  
  54.     # This is done for the user's convenience so that they don't
  55.     # have to worry about undefined hashrefs
  56.     $self->_options->{$_} = {} for HANDLES;
  57.     $self->hash_init(%$args);
  58. }
  59.  
  60. __PACKAGE__->meta->make_immutable;
  61.  
  62. 1;
  63.  
  64. =head1 NAME
  65.  
  66. GnuPG::Handles - GnuPG handles bundle
  67.  
  68. =head1 SYNOPSIS
  69.  
  70.   use IO::Handle;
  71.   my ( $stdin, $stdout, $stderr,
  72.        $status_fh, $logger_fh, $passphrase_fh,
  73.      )
  74.     = ( IO::Handle->new(), IO::Handle->new(), IO::Handle->new(),
  75.         IO::Handle->new(), IO::Handle->new(), IO::Handle->new(),
  76.       );
  77.  
  78.   my $handles = GnuPG::Handles->new
  79.     ( stdin      => $stdin,
  80.       stdout     => $stdout,
  81.       stderr     => $stderr,
  82.       status     => $status_fh,
  83.       logger     => $logger_fh,
  84.       passphrase => $passphrase_fh,
  85.     );
  86.  
  87. =head1 DESCRIPTION
  88.  
  89. GnuPG::Handles objects are generally instantiated
  90. to be used in conjunction with methods of objects
  91. of the class GnuPG::Interface.  GnuPG::Handles objects
  92. represent a collection of handles that are used to
  93. communicate with GnuPG.
  94.  
  95. =head1 OBJECT METHODS
  96.  
  97. =head2 Initialization Methods
  98.  
  99. =over 4
  100.  
  101. =item new( I<%initialization_args> )
  102.  
  103. This methods creates a new object.  The optional arguments are
  104. initialization of data members.
  105.  
  106. =item hash_init( I<%args> ).
  107.  
  108.  
  109. =back
  110.  
  111. =head1 OBJECT DATA MEMBERS
  112.  
  113. =over 4
  114.  
  115. =item stdin
  116.  
  117. This handle is connected to the standard input of a GnuPG process.
  118.  
  119. =item stdout
  120.  
  121. This handle is connected to the standard output of a GnuPG process.
  122.  
  123. =item stderr
  124.  
  125. This handle is connected to the standard error of a GnuPG process.
  126.  
  127. =item status
  128.  
  129. This handle is connected to the status output handle of a GnuPG process.
  130.  
  131. =item logger
  132.  
  133. This handle is connected to the logger output handle of a GnuPG process.
  134.  
  135. =item passphrase
  136.  
  137. This handle is connected to the passphrase input handle of a GnuPG process.
  138.  
  139. =item command
  140.  
  141. This handle is connected to the command input handle of a GnuPG process.
  142.  
  143. =item options
  144.  
  145. This is a hash of hashrefs of settings pertaining to the handles
  146. in this object.  The outer-level hash is keyed by the names of the
  147. handle the setting is for, while the inner is keyed by the setting
  148. being referenced.  For example, to set the setting C<direct> to true
  149. for the filehandle C<stdin>, the following code will do:
  150.  
  151.     # assuming $handles is an already-created
  152.     # GnuPG::Handles object, this sets all
  153.     # options for the filehandle stdin in one blow,
  154.     # clearing out all others
  155.     $handles->options( 'stdin', { direct => 1 } );
  156.  
  157.     # this is useful to just make one change
  158.     # to the set of options for a handle
  159.     $handles->options( 'stdin' )->{direct} = 1;
  160.  
  161.     # and to get the setting...
  162.     $setting = $handles->options( 'stdin' )->{direct};
  163.  
  164.     # and to clear the settings for stdin
  165.     $handles->options( 'stdin', {} );
  166.  
  167. The currently-used settings are as follows:
  168.  
  169. =over 4
  170.  
  171. =item direct
  172.  
  173. If the setting C<direct> is true for a handle, the GnuPG
  174. process spawned will access the handle directly.  This is useful for
  175. having the GnuPG process read or write directly to or from
  176. an already-opened file.
  177.  
  178. =back
  179.  
  180. =back
  181.  
  182. =head1 SEE ALSO
  183.  
  184. L<GnuPG::Interface>,
  185.  
  186. =cut
  187.