| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Crypt::Random::Source::Base::Proc; | 
| 2 |  |  |  |  |  |  | # ABSTRACT: Base class for helper processes (e.g. C) | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | our $VERSION = '0.12'; | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 17368 | use Moo; | 
|  | 1 |  |  |  |  | 9338 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | extends qw(Crypt::Random::Source::Base::Handle); | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 1 |  |  | 1 |  | 2056 | use Capture::Tiny 0.08 qw(capture); | 
|  | 1 |  |  |  |  | 20078 |  | 
|  | 1 |  |  |  |  | 47 |  | 
| 11 | 1 |  |  | 1 |  | 6 | use File::Spec; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 17 |  | 
| 12 | 1 |  |  | 1 |  | 445 | use IO::File 1.14; | 
|  | 1 |  |  |  |  | 667 |  | 
|  | 1 |  |  |  |  | 93 |  | 
| 13 | 1 |  |  | 1 |  | 462 | use Types::Standard qw(Str); | 
|  | 1 |  |  |  |  | 45788 |  | 
|  | 1 |  |  |  |  | 8 |  | 
| 14 | 1 |  |  | 1 |  | 1025 | use namespace::clean; | 
|  | 1 |  |  |  |  | 7892 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 | 1 |  |  | 1 |  | 419 | use 5.008; | 
|  | 1 |  |  |  |  | 2 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | has command => ( is => "rw", required => 1 ); | 
| 19 |  |  |  |  |  |  | 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 |  |  |  |  |  |  | our $TAINT_PATH = | 
| 24 |  |  |  |  |  |  | '/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin'; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub _build_search_path { | 
| 27 |  |  |  |  |  |  | # In taint mode it's not safe to use $ENV{PATH}. | 
| 28 | 1 | 50 |  | 1 |  | 587 | if (${^TAINT}) { | 
| 29 | 0 |  |  |  |  | 0 | return $TAINT_PATH; | 
| 30 |  |  |  |  |  |  | } | 
| 31 | 1 |  |  |  |  | 14 | return $ENV{PATH}; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | sub open_handle { | 
| 35 | 1 |  |  | 1 | 1 | 1 | my $self = shift; | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 1 |  |  |  |  | 10 | my $cmd = $self->command; | 
| 38 | 1 | 50 |  |  |  | 4 | my @cmd = ref $cmd ? @$cmd : $cmd; | 
| 39 | 1 |  |  |  |  | 1 | my $retval; | 
| 40 | 1 |  |  |  |  | 4 | local $ENV{PATH} = $self->search_path; | 
| 41 | 1 |  |  | 1 |  | 36 | my ($stdout, $stderr) = capture { $retval = system(@cmd) }; | 
|  | 1 |  |  |  |  | 3069 |  | 
| 42 | 1 |  |  |  |  | 609 | chomp($stderr); | 
| 43 | 1 | 50 |  |  |  | 10 | if ($retval) { | 
| 44 | 0 |  |  |  |  | 0 | my $err = join(' ', @cmd) . ": $! ($?)"; | 
| 45 | 0 | 0 |  |  |  | 0 | if ($stderr) { | 
| 46 | 0 |  |  |  |  | 0 | $err .= "\n$stderr"; | 
| 47 |  |  |  |  |  |  | } | 
| 48 | 0 |  |  |  |  | 0 | die $err; | 
| 49 |  |  |  |  |  |  | } | 
| 50 | 1 | 50 |  |  |  | 5 | warn $stderr if $stderr; | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 1 |  |  |  |  | 11 | my $fh = IO::File->new(\$stdout, '<'); | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 1 |  |  |  |  | 869 | return $fh; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | 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) | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =head1 VERSION | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | version 0.12 | 
| 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 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. | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head1 SUPPORT | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | Bugs may be submitted through L | 
| 98 |  |  |  |  |  |  | (or L). | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =head1 AUTHOR | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | יובל קוג'מן (Yuval Kogman) | 
| 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__ |