blib/lib/CPANPLUS/Shell/Default/Plugins/Source.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 54 CC 4 SCAR 22.2
CC
4
Cov
0%
source
20.0
plugins
2.0
source_help
2.0
CRAP 9.2
1 package CPANPLUS::Shell::Default::Plugins::Source;
2  
3 use strict;
4 use CPANPLUS::Error qw[error msg];
5 use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
6  
7 use vars qw[$VERSION];
8 $VERSION = "0.9914";
9  
10 =head1 NAME
11  
12 CPANPLUS::Shell::Default::Plugins::Source - read in CPANPLUS commands
13  
14 =head1 SYNOPSIS
15  
16 CPAN Terminal> /source /tmp/list_of_commands /tmp/more_commands
17  
18 =head1 DESCRIPTION
19  
20 This is a C<CPANPLUS::Shell::Default> plugin that works just like
21 your unix shells source(1) command; it reads in a file that has
22 commands in it to execute, and then executes them.
23  
24 A sample file might look like this:
25  
26 # first, update all the source files
27 x --update_source
28  
29 # find all of my modules that are on the CPAN
30 # test them, and store the error log
31 a ^KANE$'
32 t *
33 p /home/kane/cpan-autotest/log
34  
35 # and inform us we're good to go
36 ! print "Autotest complete, log stored; please enter your commands!"
37  
38 Note how empty lines, and lines starting with a '#' are being skipped
39 in the execution.
40  
41 =cut
42  
43  
44 sub plugins { return ( source => 'source' ) }
45  
46 sub source {
47 my $class = shift;
48 my $shell = shift;
49 my $cb = shift;
50 my $cmd = shift;
51 my $input = shift || '';
52 my $opts = shift || {};
53 my $verbose = $cb->configure_object->get_conf('verbose');
54  
55 for my $file ( split /\s+/, $input ) {
56 my $fh = FileHandle->new("$file") or(
57 error(loc("Could not open file '%1': %2", $file, $!)),
58 next
59 );
60  
61 while( my $line = <$fh> ) {
62 chomp $line;
63  
64 next if $line !~ /\S+/; # skip empty/whitespace only lines
65 next if $line =~ /^#/; # skip comments
66  
67 msg(loc("Dispatching '%1'", $line), $verbose);
68 return 1 if $shell->dispatch_on_input( input => $line );
69 }
70 }
71 }
72  
73 sub source_help {
74 return loc(' /source FILE [FILE ..] '.
75 '# read in commands from the specified file' ),
76 }
77  
78 1;
79  
80 =pod
81  
82 =head1 BUG REPORTS
83  
84 Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
85  
86 =head1 AUTHOR
87  
88 This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
89  
90 =head1 COPYRIGHT
91  
92 The CPAN++ interface (of which this module is a part of) is copyright (c)
93 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
94  
95 This library is free software; you may redistribute and/or modify it
96 under the same terms as Perl itself.
97  
98 =head1 SEE ALSO
99  
100 L<CPANPLUS::Shell::Default>, L<CPANPLUS::Shell>, L<cpanp>
101  
102 =cut
103  
104 # Local variables:
105 # c-indentation-style: bsd
106 # c-basic-offset: 4
107 # indent-tabs-mode: nil
108 # End:
109 # vim: expandtab shiftwidth=4:
110