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