| 1 | package Crypt::Random::Source::Base::Proc; | ||||||||||
| 2 | # ABSTRACT: Base class for helper processes (e.g. C<openssl>) | ||||||||||
| 3 | |||||||||||
| 4 | 1 | our $VERSION = '0.14'; | |||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | extends qw(Crypt::Random::Source::Base::Handle); | |||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use Capture::Tiny 0.08 qw(capture); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use IO::File 1.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Types::Standard qw(Str); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 1 | has command => ( is => "rw", required => 1 ); | |||||||||
| 19 | 1 | has search_path => ( is => 'rw', isa => Str, lazy => 1, builder => 1); | |||||||||
| 20 | |||||||||||
| 21 | # This is a scalar so that people can customize it (which they would | ||||||||||
| 22 | # particularly need to do on Windows). | ||||||||||
| 23 | 1 | our $TAINT_PATH = | |||||||||
| 24 | '/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin'; | ||||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | sub _build_search_path { | ||||||||
|
Subroutine
_build_search_path: called CC=2 SCAR=8.1
| |||||||||||
| 27 | # In taint mode it's not safe to use $ENV{PATH}. | ||||||||||
| 28 | 1 | ▶ | if (${^TAINT}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | return $TAINT_PATH; | |||||||||
| 30 | } | ||||||||||
| 31 | 1 | return $ENV{PATH}; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 1 | ▶ | sub open_handle { | ||||||||
|
Subroutine
open_handle: called CC=5 SCAR=18.4
Pod
documented
| |||||||||||
| 35 | 1 | my $self = shift; | |||||||||
| 36 | |||||||||||
| 37 | 1 | my $cmd = $self->command; | |||||||||
| 38 | 1 | ▶ | my @cmd = ref $cmd ? @$cmd : $cmd; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 1 | my $retval; | |||||||||
| 40 | 1 | local $ENV{PATH} = $self->search_path; | |||||||||
| 41 | 1 | ▶ | my ($stdout, $stderr) = capture { $retval = system(@cmd) }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 42 | 1 | chomp($stderr); | |||||||||
| 43 | 1 | ▶ | if ($retval) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | my $err = join(' ', @cmd) . ": $! ($?)"; | |||||||||
| 45 | 0 | ▶ | if ($stderr) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | $err .= "\n$stderr"; | |||||||||
| 47 | } | ||||||||||
| 48 | 0 | die $err; | |||||||||
| 49 | } | ||||||||||
| 50 | 1 | ▶ | warn $stderr if $stderr; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 1 | my $fh = IO::File->new(\$stdout, '<'); | |||||||||
| 53 | |||||||||||
| 54 | 1 | return $fh; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | 1; | |||||||||
| 58 | |||||||||||
| 59 | =pod | ||||||||||
| 60 | |||||||||||
| 61 | =encoding UTF-8 | ||||||||||
| 62 | |||||||||||
| 63 | =head1 NAME | ||||||||||
| 64 | |||||||||||
| 65 | Crypt::Random::Source::Base::Proc - Base class for helper processes (e.g. C<openssl>) | ||||||||||
| 66 | |||||||||||
| 67 | =head1 VERSION | ||||||||||
| 68 | |||||||||||
| 69 | version 0.14 | ||||||||||
| 70 | |||||||||||
| 71 | =head1 SYNOPSIS | ||||||||||
| 72 | |||||||||||
| 73 | use Moo; | ||||||||||
| 74 | extends qw(Crypt::Random::Source::Base::Proc); | ||||||||||
| 75 | |||||||||||
| 76 | has '+command' => ( default => ... ); | ||||||||||
| 77 | |||||||||||
| 78 | =head1 DESCRIPTION | ||||||||||
| 79 | |||||||||||
| 80 | This is a base class for using command line utilities which output random data | ||||||||||
| 81 | on STDOUT as L<Crypt::Random::Source> objects. | ||||||||||
| 82 | |||||||||||
| 83 | =head1 ATTRIBUTES | ||||||||||
| 84 | |||||||||||
| 85 | =head2 command | ||||||||||
| 86 | |||||||||||
| 87 | An array reference or string that is the command to run. | ||||||||||
| 88 | |||||||||||
| 89 | =head1 METHODS | ||||||||||
| 90 | |||||||||||
| 91 | =head2 open_handle | ||||||||||
| 92 | |||||||||||
| 93 | Opens a pipe for reading using C<command>. | ||||||||||
| 94 | |||||||||||
| 95 | =head1 SUPPORT | ||||||||||
| 96 | |||||||||||
| 97 | Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Crypt-Random-Source> | ||||||||||
| 98 | (or L<bug-Crypt-Random-Source@rt.cpan.org|mailto:bug-Crypt-Random-Source@rt.cpan.org>). | ||||||||||
| 99 | |||||||||||
| 100 | =head1 AUTHOR | ||||||||||
| 101 | |||||||||||
| 102 | יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> | ||||||||||
| 103 | |||||||||||
| 104 | =head1 COPYRIGHT AND LICENCE | ||||||||||
| 105 | |||||||||||
| 106 | This software is copyright (c) 2008 by Yuval Kogman. | ||||||||||
| 107 | |||||||||||
| 108 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 109 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 110 | |||||||||||
| 111 | =cut | ||||||||||
| 112 | |||||||||||
| 113 | __END__ | ||||||||||