| 1 | # | ||||||||||||||
| 2 | # This file is part of Tee | ||||||||||||||
| 3 | # | ||||||||||||||
| 4 | # This software is Copyright (c) 2006 by David Golden. | ||||||||||||||
| 5 | # | ||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||
| 7 | # | ||||||||||||||
| 8 | # The Apache License, Version 2.0, January 2004 | ||||||||||||||
| 9 | # | ||||||||||||||
| 10 | 5 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 5 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | package Tee::App; | ||||||||||||||
| 13 | 5 | ▶ | BEGIN { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 5 | $Tee::App::VERSION = '0.14'; | |||||||||||||
| 15 | } | ||||||||||||||
| 16 | # ABSTRACT: Implementation of ptee | ||||||||||||||
| 17 | |||||||||||||||
| 18 | 5 | ▶ | use Exporter (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | 5 | ▶ | use File::Basename qw/basename/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | 5 | ▶ | use Getopt::Long; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 21 | 5 | ▶ | use IO::File; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 5 | our @ISA = 'Exporter'; | |||||||||||||
| 23 | 5 | our @EXPORT = qw/run/; | |||||||||||||
| 24 | |||||||||||||||
| 25 | #--------------------------------------------------------------------------# | ||||||||||||||
| 26 | # define help text | ||||||||||||||
| 27 | #--------------------------------------------------------------------------# | ||||||||||||||
| 28 | |||||||||||||||
| 29 | 5 | my $help_text = <<'END_HELP'; | |||||||||||||
| 30 | |||||||||||||||
| 31 | ptee [OPTIONS]... [FILENAMES]... | ||||||||||||||
| 32 | |||||||||||||||
| 33 | OPTIONS: | ||||||||||||||
| 34 | |||||||||||||||
| 35 | --append or -a | ||||||||||||||
| 36 | append to file(s) rather than overwrite | ||||||||||||||
| 37 | |||||||||||||||
| 38 | --help or -h | ||||||||||||||
| 39 | give usage information | ||||||||||||||
| 40 | |||||||||||||||
| 41 | --version or -V | ||||||||||||||
| 42 | print the version number of this program | ||||||||||||||
| 43 | |||||||||||||||
| 44 | END_HELP | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 5 | $help_text =~ s/\A.+?( ptee.*)/$1/ms; | |||||||||||||
| 47 | |||||||||||||||
| 48 | 4 | ▶ | sub run { | ||||||||||||
|
Subroutine
run: called CC=8 SCAR=31.4
Pod
undocumented
| |||||||||||||||
| 49 | |||||||||||||||
| 50 | #--------------------------------------------------------------------------# | ||||||||||||||
| 51 | # process command line | ||||||||||||||
| 52 | #--------------------------------------------------------------------------# | ||||||||||||||
| 53 | |||||||||||||||
| 54 | 0 | ▶ | my %opts; | ||||||||||||
|
Subroutine
run: not called CC=8 SCAR=31.4
Pod
undocumented
| |||||||||||||||
| 55 | 0 | GetOptions( \%opts, | |||||||||||||
| 56 | 'version|V', | ||||||||||||||
| 57 | 'help|h|?', | ||||||||||||||
| 58 | 'append|a', | ||||||||||||||
| 59 | ); | ||||||||||||||
| 60 | |||||||||||||||
| 61 | #--------------------------------------------------------------------------# | ||||||||||||||
| 62 | # options | ||||||||||||||
| 63 | #--------------------------------------------------------------------------# | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 0 | ▶ | if ($opts{version}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 66 | 0 | print basename($0), " $main::VERSION\n"; | |||||||||||||
| 67 | 0 | exit 0; | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | 0 | ▶ | if ($opts{help}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 71 | 0 | print "Usage:\n$help_text"; | |||||||||||||
| 72 | 0 | exit 1; | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 0 | ▶ | my $mode = $opts{append} ? ">>" : ">"; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 76 | |||||||||||||||
| 77 | #--------------------------------------------------------------------------# | ||||||||||||||
| 78 | # Setup list of filehandles | ||||||||||||||
| 79 | #--------------------------------------------------------------------------# | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 0 | my @files; | |||||||||||||
| 82 | |||||||||||||||
| 83 | 0 | for my $file ( @ARGV ) { | |||||||||||||
| 84 | 0 | ▶ | my $f = IO::File->new("$mode $file") | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 85 | or die "Could't open '$file' for writing: $!'"; | ||||||||||||||
| 86 | 0 | push @files, $f; | |||||||||||||
| 87 | } | ||||||||||||||
| 88 | |||||||||||||||
| 89 | #--------------------------------------------------------------------------# | ||||||||||||||
| 90 | # Tee input to the filehandle list | ||||||||||||||
| 91 | #--------------------------------------------------------------------------# | ||||||||||||||
| 92 | |||||||||||||||
| 93 | 0 | my $buffer_size = 1024; | |||||||||||||
| 94 | 0 | my $buffer; | |||||||||||||
| 95 | |||||||||||||||
| 96 | 0 | ▶ | while ( sysread( STDIN, $buffer, $buffer_size ) > 0 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 97 | 0 | syswrite STDOUT, $buffer; | |||||||||||||
| 98 | 0 | for my $fh ( @files ) { | |||||||||||||
| 99 | 0 | syswrite $fh, $buffer; | |||||||||||||
| 100 | } | ||||||||||||||
| 101 | } | ||||||||||||||
| 102 | 0 | return; | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | 5 | 1; | |||||||||||||
| 106 | |||||||||||||||
| 107 | |||||||||||||||
| 108 | |||||||||||||||
| 109 | =pod | ||||||||||||||
| 110 | |||||||||||||||
| 111 | =head1 NAME | ||||||||||||||
| 112 | |||||||||||||||
| 113 | Tee::App - Implementation of ptee | ||||||||||||||
| 114 | |||||||||||||||
| 115 | =head1 VERSION | ||||||||||||||
| 116 | |||||||||||||||
| 117 | version 0.14 | ||||||||||||||
| 118 | |||||||||||||||
| 119 | =head1 DESCRIPTION | ||||||||||||||
| 120 | |||||||||||||||
| 121 | Guts of the C<<< ptee >>> command. | ||||||||||||||
| 122 | |||||||||||||||
| 123 | =for Pod::Coverage run | ||||||||||||||
| 124 | |||||||||||||||
| 125 | =head1 SEE ALSO | ||||||||||||||
| 126 | |||||||||||||||
| 127 | =over | ||||||||||||||
| 128 | |||||||||||||||
| 129 | =item * | ||||||||||||||
| 130 | |||||||||||||||
| 131 | L<ptee> | ||||||||||||||
| 132 | |||||||||||||||
| 133 | =back | ||||||||||||||
| 134 | |||||||||||||||
| 135 | =head1 BUGS | ||||||||||||||
| 136 | |||||||||||||||
| 137 | Please report any bugs or feature using the CPAN Request Tracker. | ||||||||||||||
| 138 | Bugs can be submitted through the web interface at | ||||||||||||||
| 139 | L<http://rt.cpan.org/Dist/Display.html?Queue=Tee> | ||||||||||||||
| 140 | |||||||||||||||
| 141 | When submitting a bug or request, please include a test-file or a patch to an | ||||||||||||||
| 142 | existing test-file that illustrates the bug or desired feature. | ||||||||||||||
| 143 | |||||||||||||||
| 144 | =head1 AUTHOR | ||||||||||||||
| 145 | |||||||||||||||
| 146 | David Golden <dagolden@cpan.org> | ||||||||||||||
| 147 | |||||||||||||||
| 148 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 149 | |||||||||||||||
| 150 | This software is Copyright (c) 2006 by David Golden. | ||||||||||||||
| 151 | |||||||||||||||
| 152 | This is free software, licensed under: | ||||||||||||||
| 153 | |||||||||||||||
| 154 | The Apache License, Version 2.0, January 2004 | ||||||||||||||
| 155 | |||||||||||||||
| 156 | =cut | ||||||||||||||
| 157 | |||||||||||||||
| 158 | |||||||||||||||
| 159 | __END__ | ||||||||||||||