-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2618ee5
Showing
12 changed files
with
542 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source $HOME/.screenrc | ||
|
||
screen 0 | ||
stuff "[ -s Session.vim ] || vim -c 'mks!' -c 'quit'; vim -S \015" | ||
screen 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
0.001 Friday October 23 03:23:23 PDT 2009: | ||
Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.PHONY: all test clean distclean dist | ||
|
||
all: test | ||
|
||
dist: | ||
rm -rf inc META.y*ml | ||
perl Makefile.PL | ||
$(MAKE) -f Makefile dist | ||
|
||
install distclean tardist: Makefile | ||
$(MAKE) -f $< $@ | ||
|
||
test: Makefile | ||
TEST_RELEASE=1 $(MAKE) -f $< $@ | ||
|
||
Makefile: Makefile.PL | ||
perl $< | ||
|
||
clean: distclean | ||
|
||
reset: clean | ||
perl Makefile.PL | ||
$(MAKE) test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Changes | ||
MANIFEST | ||
Makefile.PL | ||
README | ||
lib/IPC/RunSession/Simple.pm | ||
inc/Module/AutoInstall.pm | ||
inc/Module/Install.pm | ||
inc/Module/Install/AutoInstall.pm | ||
inc/Module/Install/Base.pm | ||
inc/Module/Install/Can.pm | ||
inc/Module/Install/Fetch.pm | ||
inc/Module/Install/Include.pm | ||
inc/Module/Install/Makefile.pm | ||
inc/Module/Install/Metadata.pm | ||
inc/Module/Install/Win32.pm | ||
inc/Module/Install/WriteAll.pm | ||
META.yml | ||
t/01-basic.t | ||
t/assets/basic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use inc::Module::Install; | ||
|
||
name 'IPC-RunSession-Simple'; | ||
all_from 'lib/IPC/RunSession/Simple.pm'; | ||
author q{Robert Krimen <rkrimen@cpan.org>}; | ||
license 'perl'; | ||
|
||
resources repository => 'http://github.com/robertkrimen/IPC-RunSession-Simple'; | ||
|
||
{ | ||
require ExtUtils::MakeMaker; | ||
use strict; | ||
no strict 'refs'; | ||
|
||
my $libscan = \&{"ExtUtils::MM_Any::libscan"}; | ||
*{"ExtUtils::MM_Any::libscan"} = sub { | ||
return '' unless $libscan->(@_); | ||
return '' if $_[1] =~ /\.sw[p-z]$/; | ||
return $_[1]; | ||
}; | ||
} | ||
|
||
{ | ||
map { my ($pk, $vr) = split m/\s/; build_requires $pk => $vr || 0 } grep { ! /^\s*#/ } split m/\n/, <<_END_; | ||
Test::Most | ||
_END_ | ||
|
||
map { my ($pk, $vr) = split m/\s/; requires $pk => $vr || 0 } grep { ! /^\s*#/ } split m/\n/, <<_END_; | ||
IPC::Open3 | ||
IO::Select | ||
Any::Moose | ||
_END_ | ||
} | ||
|
||
if (-e 'inc/.author') { | ||
my $all_from = join '/', 'lib', split m/-/, name . '.pm'; | ||
`perldoc -tF $all_from > README` if ! -e 'README' || (stat $all_from)[9] > (stat 'README')[9]; | ||
} | ||
|
||
auto_install; | ||
|
||
WriteAll; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
NAME | ||
IPC::RunSession::Simple - Run a simple IPC session in the same vein as | ||
IPC::Run & Expect | ||
|
||
VERSION | ||
Version 0.001 | ||
|
||
SYNOPSIS | ||
use IPC::RunSession::Simple | ||
|
||
$session = IPC::RunSession::Simple->open( "fcsh" ) | ||
|
||
# Read until the prompt (which doesn't end in a newline) | ||
# Timeout after 5 seconds | ||
$result = $session->read_until( qr/\(fcsh\) /, 5 ) | ||
|
||
if ( $result->closed ) { | ||
# We encountered an (abnormal) EOF... | ||
} | ||
elsif ( $result->expired ) { | ||
# The timeout got triggered... | ||
} | ||
else { | ||
print $result->content | ||
} | ||
|
||
# Tell 'fcsh' we want to quit | ||
$session->write( "quit\n" ) | ||
|
||
DESCRIPTION | ||
A simple IPC session with read/write capability using IPC::Open3 and | ||
IO::Select | ||
|
||
SEE ALSO | ||
IPC::Run | ||
|
||
Expect | ||
|
||
AUTHOR | ||
Robert Krimen, "<rkrimen at cpan.org>" | ||
|
||
BUGS | ||
Please report any bugs or feature requests to "bug-ipc-runsession-simple | ||
at rt.cpan.org", or through the web interface at | ||
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IPC-RunSession-Simple>. | ||
I will be notified, and then you'll automatically be notified of | ||
progress on your bug as I make changes. | ||
|
||
SUPPORT | ||
You can find documentation for this module with the perldoc command. | ||
|
||
perldoc IPC::RunSession::Simple | ||
|
||
You can also look for information at: | ||
|
||
* RT: CPAN's request tracker | ||
|
||
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=IPC-RunSession-Simple> | ||
|
||
* AnnoCPAN: Annotated CPAN documentation | ||
|
||
<http://annocpan.org/dist/IPC-RunSession-Simple> | ||
|
||
* CPAN Ratings | ||
|
||
<http://cpanratings.perl.org/d/IPC-RunSession-Simple> | ||
|
||
* Search CPAN | ||
|
||
<http://search.cpan.org/dist/IPC-RunSession-Simple/> | ||
|
||
ACKNOWLEDGEMENTS | ||
COPYRIGHT & LICENSE | ||
Copyright 2009 Robert Krimen. | ||
|
||
This program is free software; you can redistribute it and/or modify it | ||
under the terms of either: the GNU General Public License as published | ||
by the Free Software Foundation; or the Artistic License. | ||
|
||
See http://dev.perl.org/licenses/ for more information. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
package IPC::RunSession::Simple; | ||
|
||
use warnings; | ||
use strict; | ||
|
||
=head1 NAME | ||
IPC::RunSession::Simple - Run a simple IPC session in the same vein as IPC::Run & Expect | ||
=head1 VERSION | ||
Version 0.001 | ||
=head1 SYNOPSIS | ||
use IPC::RunSession::Simple | ||
$session = IPC::RunSession::Simple->open( "fcsh" ) | ||
# Read until the prompt (which doesn't end in a newline) | ||
# Timeout after 5 seconds | ||
$result = $session->read_until( qr/\(fcsh\) /, 5 ) | ||
if ( $result->closed ) { | ||
# We encountered an (abnormal) EOF... | ||
} | ||
elsif ( $result->expired ) { | ||
# The timeout got triggered... | ||
} | ||
else { | ||
print $result->content | ||
} | ||
# Tell 'fcsh' we want to quit | ||
$session->write( "quit\n" ) | ||
=head1 DESCRIPTION | ||
A simple IPC session with read/write capability using L<IPC::Open3> and L<IO::Select> | ||
=cut | ||
|
||
our $VERSION = '0.001'; | ||
|
||
use IPC::Open3 qw/ open3 /; | ||
|
||
sub open { | ||
my $class = shift; | ||
my $cmd = shift; | ||
|
||
my ( $writer, $reader ); | ||
|
||
# .., undef, ... means that the output (reader) and error handle will be on the same "stream" | ||
# open3 will not return on error... it'll die! | ||
$cmd = [ $cmd ] unless ref $cmd eq 'ARRAY'; | ||
open3 $writer, $reader, undef, @$cmd; | ||
|
||
return IPC::RunSession::Simple::Session->new( writer => $writer, reader => $reader ); | ||
} | ||
|
||
sub new { | ||
return shift->open( @_ ); | ||
} | ||
|
||
sub run { | ||
return shift->open( @_ ); | ||
} | ||
|
||
package IPC::RunSession::Simple::Session; | ||
|
||
use Any::Moose; | ||
|
||
use IO::Select; | ||
|
||
has [qw/ writer reader /] => qw/is ro required 1/; | ||
has _selector => qw/is ro lazy_build 1/; | ||
sub _build__selector { | ||
my $self = shift; | ||
my $selector = IO::Select->new; | ||
$selector->add( $self->reader ); | ||
return $selector; | ||
} | ||
has _read_amount => qw/is rw/, default => 10_000; | ||
|
||
sub read { | ||
my $self = shift; | ||
my $timeout = shift; | ||
|
||
return $self->read_until( undef, $timeout ); | ||
} | ||
|
||
sub read_until { | ||
my $self = shift; | ||
my $marker = shift; | ||
my $timeout = shift; | ||
|
||
my $result = IPC::RunSession::Simple::Session::Result->new; | ||
my $content = ''; | ||
|
||
while ( 1 ) { | ||
if ( $self->_selector->can_read( $timeout ) ) { | ||
|
||
my $read_size = sysread $self->reader, my $read, $self->_read_amount; | ||
if ( ! $read_size ) { # Reached EOF... | ||
$result->closed( 1 ); | ||
last; | ||
} | ||
else { | ||
$content .= $read; | ||
last unless $marker; | ||
|
||
if ( ref $marker eq 'Regexp' ) { | ||
last if $content =~ $marker; | ||
} | ||
elsif ( ref $marker eq 'CODE' ) { | ||
last if $marker->( $content ); | ||
} | ||
else { | ||
die "Don't understand marker ($marker)"; | ||
} | ||
} | ||
} | ||
else { | ||
$result->expired( 1 ); | ||
last; | ||
} | ||
} | ||
|
||
$result->content( $content ); | ||
|
||
return $result; | ||
} | ||
|
||
sub write { | ||
my $self = shift; | ||
my $content = shift; | ||
|
||
my $writer = $self->writer; | ||
print $writer $content; | ||
} | ||
|
||
package IPC::RunSession::Simple::Session::Result; | ||
|
||
use Any::Moose; | ||
|
||
has [qw/ content closed expired /] => qw/is rw/; | ||
|
||
=head1 SEE ALSO | ||
L<IPC::Run> | ||
L<Expect> | ||
=head1 AUTHOR | ||
Robert Krimen, C<< <rkrimen at cpan.org> >> | ||
=head1 BUGS | ||
Please report any bugs or feature requests to C<bug-ipc-runsession-simple at rt.cpan.org>, or through | ||
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IPC-RunSession-Simple>. I will be notified, and then you'll | ||
automatically be notified of progress on your bug as I make changes. | ||
=head1 SUPPORT | ||
You can find documentation for this module with the perldoc command. | ||
perldoc IPC::RunSession::Simple | ||
You can also look for information at: | ||
=over 4 | ||
=item * RT: CPAN's request tracker | ||
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=IPC-RunSession-Simple> | ||
=item * AnnoCPAN: Annotated CPAN documentation | ||
L<http://annocpan.org/dist/IPC-RunSession-Simple> | ||
=item * CPAN Ratings | ||
L<http://cpanratings.perl.org/d/IPC-RunSession-Simple> | ||
=item * Search CPAN | ||
L<http://search.cpan.org/dist/IPC-RunSession-Simple/> | ||
=back | ||
=head1 ACKNOWLEDGEMENTS | ||
=head1 COPYRIGHT & LICENSE | ||
Copyright 2009 Robert Krimen. | ||
This program is free software; you can redistribute it and/or modify it | ||
under the terms of either: the GNU General Public License as published | ||
by the Free Software Foundation; or the Artistic License. | ||
See http://dev.perl.org/licenses/ for more information. | ||
=cut | ||
|
||
1; # End of IPC::RunSession::Simple |
Oops, something went wrong.