Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Missed parts of dzil migration. Add ability to pass in your own

Term::ReadLine object to constructors.  Just to be flexible.
  • Loading branch information...
commit c5a2e9f0cfa3a8c57959a2d0eb5ffb7b122ec686 1 parent c581768
@dmcbride authored
View
1  .gitignore
@@ -1,5 +1,6 @@
*.bak
Build
+.build
blib/*
_build
MYMETA.*
View
35 dist.ini
@@ -0,0 +1,35 @@
+name = Term-ReadLine-Event
+author = Darin McBride <dmcbride@cpan.org>
+license = Perl_5
+copyright_holder = Darin McBride and others
+version = 0.01
+
+
+[@Git]
+
+[@Basic]
+[PkgVersion]
+
+[PodWeaver]
+[PodSyntaxTests]
+
+[ModuleBuild]
+[DualBuilders]
+[MetaJSON]
+
+[AutoPrereqs]
+skip = ^Coro::
+
+[Prereqs / Suggests]
+AnyEvent = 0
+Coro = 0
+IO::Async = 0
+IO::Poll = 0
+POE = 0
+Reflex = 0
+
+[MetaResources]
+repository.type = git
+repository.web = https://github.com/dmcbride/Term-ReadLine-Event
+repository.url = git://github.com/dmcbride/Term-ReadLine-Event.git
+
View
45 lib/Term/ReadLine/Event.pm
@@ -5,6 +5,7 @@ use strict;
use warnings;
use Term::ReadLine 1.09;
+use Scalar::Util qw(blessed);
# ABSTRACT: Wrappers for Term::ReadLine's new event_loop model.
@@ -16,7 +17,7 @@ as a small change to your code rather than the longer code required.
use AnyEvent;
use Term::ReadLine::Event;
- my $term = Term::ReadLine::Event->with_AnyEvent();
+ my $term = Term::ReadLine::Event->with_AnyEvent('...');
my $input = $term->readline('Prompt >');
@@ -81,23 +82,46 @@ I'd be writing in C.
=head1 METHODS
-All constructors (C<with_>*) take as their first parameter the name
-of the application, which gets passed in to Term::ReadLine's constructor.
+All constructors (C<with_>*) take as their first parameter one of:
-If you need to use more parameters to Term::ReadLine's constructor, such
-as specifying the input and output filehandles, then pass all of the
-parameters for Term::ReadLine in as an anonymous array ref:
+=over 4
+
+=item *
+
+The name of the application, which gets passed in to Term::ReadLine's
+constructor.
+
+ my $term = Term::ReadLine::Event->with_Foo('myapp');
+
+=item *
+
+An array ref consisting of the name of the application, and the input
+and output filehandles. This is useful if you need to override
+these filehandles.
- Term::ReadLine::Event->with_Foo(['myapp', \*STDIN, \*STDOUT]);
+ my $term = Term::ReadLine::Event->with_Foo(['myapp', \*STDIN, \*STDOUT]);
+
+=item *
+
+A pre-constructed Term::ReadLine object. This is useful if you need
+to do other things with the Term::ReadLine object prior to setting up
+the event loop, or if you have a custom package derived from Term::ReadLine
+and you do not want Term::ReadLine::Event to create the default type.
+
+ my $term = Term::ReadLine::Special->new('myapp', other => 'stuff');
+ $term = Term::ReadLine::Event->with_Foo($term);
+
+=back
Paramters for setting up the event loop, if any are required, will be
-after the application name or array ref as named parameters, e.g.:
+after this first parameter as named parameters, e.g.:
Term::ReadLine::Event->with_IO_Async('myapp', loop => $loop);
All constructors also assume that the required module(s) is(are) already
loaded. That is, if you're using with_AnyEvent, you have already loaded
-AnyEvent; if you're using with_POE, you have already loaded POE, etc.
+AnyEvent (and thus the event loop it is using); if you're using with_POE,
+you have already loaded POE, etc.
=head2 with_AnyEvent
@@ -111,7 +135,8 @@ sub _new {
my $self = bless {@_}, $class;
- $self->{_term} = Term::ReadLine->new(ref $app ? @$app : $app);
+ $self->{_term} = blessed $app ? $app :
+ Term::ReadLine->new(ref $app ? @$app : $app);
$self;
}
View
31 t/40-custom_trl.t
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+
+BEGIN { $ENV{PERL_RL} = 'Stub'; }
+BEGIN { $^W = 0 } # common::sense does funny things, we don't need to hear about it.
+
+package Term::ReadLine::Test;
+
+use parent 'Term::ReadLine';
+sub new
+{
+ my $class = shift;
+ my $obj = $class->SUPER::new(@_);
+ bless $obj, $class;
+}
+
+package main;
+
+use Test::More;
+BEGIN {
+ plan skip_all => "AnyEvent is not installed" unless eval "use AnyEvent; 1";
+}
+plan tests => 1;
+
+use Term::ReadLine 1.09;
+use Term::ReadLine::Event;
+
+my $term = Term::ReadLine::Test->new('foo');
+$term = Term::ReadLine::Event->with_AnyEvent($term);
+isa_ok($term->trl() => 'Term::ReadLine::Test');
+
View
9 xt/release/manifest.t
@@ -0,0 +1,9 @@
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More;
+
+eval "use Test::CheckManifest 0.9";
+plan skip_all => "Test::CheckManifest 0.9 required" if $@;
+ok_manifest();
Please sign in to comment.
Something went wrong with that request. Please try again.