home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / perl / 5.10.0 / CPANPLUS / Shell / Default / Plugins / Source.pm < prev   
Encoding:
Perl POD Document  |  2009-06-26  |  2.6 KB  |  108 lines

  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. =head1 NAME
  8.  
  9. CPANPLUS::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.  
  17. This is a C<CPANPLUS::Shell::Default> plugin that works just like
  18. your unix shells source(1) command; it reads in a file that has
  19. commands in it to execute, and then executes them.
  20.  
  21. A 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.  
  35. Note how empty lines, and lines starting with a '#' are being skipped
  36. in the execution.
  37.  
  38. =cut
  39.  
  40.  
  41. sub plugins { return ( source => 'source' ) }
  42.  
  43. sub 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.  
  70. sub source_help {
  71.     return loc('    /source FILE [FILE ..] '.
  72.                '# read in commands from the specified file' ),
  73. }
  74.  
  75. 1;
  76.  
  77. =pod
  78.  
  79. =head1 BUG REPORTS
  80.  
  81. Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
  82.  
  83. =head1 AUTHOR
  84.  
  85. This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
  86.  
  87. =head1 COPYRIGHT
  88.  
  89. The CPAN++ interface (of which this module is a part of) is copyright (c) 
  90. 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
  91.  
  92. This library is free software; you may redistribute and/or modify it 
  93. under the same terms as Perl itself.
  94.  
  95. =head1 SEE ALSO
  96.  
  97. L<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.  
  108.