[Bast-commits] r3391 - in trunk/Devel-REPL: . lib/Devel
lib/Devel/REPL script
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Tue May 29 00:20:56 GMT 2007
Author: matthewt
Date: 2007-05-29 00:20:56 +0100 (Tue, 29 May 2007)
New Revision: 3391
Added:
trunk/Devel-REPL/Makefile.PL
trunk/Devel-REPL/lib/Devel/REPL/Script.pm
trunk/Devel-REPL/script/
trunk/Devel-REPL/script/re.pl
Modified:
trunk/Devel-REPL/lib/Devel/REPL.pm
Log:
basic packaging code
Added: trunk/Devel-REPL/Makefile.PL
===================================================================
--- trunk/Devel-REPL/Makefile.PL (rev 0)
+++ trunk/Devel-REPL/Makefile.PL 2007-05-28 23:20:56 UTC (rev 3391)
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use inc::Module::Install 0.67;
+
+name 'Devel-REPL';
+all_from 'lib/Devel/REPL.pm';
+
+install_script 'script/re.pl';
+
+requires 'Moose';
+requires 'MooseX::Object::Pluggable';
+requires 'namespace::clean';
+requires 'File::HomeDir';
+requires 'File::Spec';
+requires 'Term::ReadLine';
+
+auto_install;
+WriteAll;
Added: trunk/Devel-REPL/lib/Devel/REPL/Script.pm
===================================================================
--- trunk/Devel-REPL/lib/Devel/REPL/Script.pm (rev 0)
+++ trunk/Devel-REPL/lib/Devel/REPL/Script.pm 2007-05-28 23:20:56 UTC (rev 3391)
@@ -0,0 +1,61 @@
+package Devel::REPL::Script;
+
+use Moose;
+use Devel::REPL;
+use File::HomeDir;
+use File::Spec;
+use namespace::clean -except => [ qw(meta) ];
+
+with 'MooseX::Getopt';
+
+has 'rcfile' => (
+ is => 'ro', isa => 'Str', required => 1, default => sub { 'repl.rc' },
+);
+
+has '_repl' => (
+ is => 'ro', isa => 'Devel::REPL', required => 1,
+ default => sub { Devel::REPL->new() }
+);
+
+sub BUILD {
+ my ($self) = @_;
+ $self->load_rcfile;
+}
+
+sub load_rcfile {
+ my ($self) = @_;
+
+ my $rc_file = $self->rcfile;
+
+ # plain name => ~/.re.pl/${rc_file}
+ if ($rc_file !~ m!/!) {
+ $rc_file = File::Spec->catfile(File::HomeDir->my_home, '.re.pl', $rc_file);
+ }
+
+ if (-r $rc_file) {
+ open RCFILE, '<', $rc_file || die "Couldn't open ${rc_file}: $!";
+ my $rc_data;
+ { local $/; $rc_data = <RCFILE>; }
+ close RCFILE; # Don't care if this fails
+ $self->eval_rcdata($rc_data);
+ warn "Error executing rc file ${rc_file}: $@\n" if $@;
+ }
+}
+
+sub eval_rcdata {
+ my $_REPL = $_[0]->_repl;
+ eval $_[1];
+}
+
+sub run {
+ my ($self) = @_;
+ $self->_repl->run;
+}
+
+sub import {
+ my ($class, @opts) = @_;
+ return unless (@opts == 1 && $opts[0] eq 'run');
+ $class->new_with_options->run;
+}
+
+1;
Modified: trunk/Devel-REPL/lib/Devel/REPL.pm
===================================================================
--- trunk/Devel-REPL/lib/Devel/REPL.pm 2007-05-28 22:42:17 UTC (rev 3390)
+++ trunk/Devel-REPL/lib/Devel/REPL.pm 2007-05-28 23:20:56 UTC (rev 3391)
@@ -3,7 +3,10 @@
use Term::ReadLine;
use Moose;
use namespace::clean -except => [ 'meta' ];
+use 5.8.1; # might work with earlier perls but probably not
+our $VERSION = '1.000000';
+
with 'MooseX::Object::Pluggable';
has 'term' => (
@@ -82,7 +85,30 @@
sub print {
my ($self, @ret) = @_;
my $fh = $self->out_fh;
+ no warnings 'uninitialized';
print $fh "@ret";
}
+=head1 NAME
+
+Devel::REPL - a modern perl interactive shell
+
+=head1 SYNOPSIS
+
+ my $repl = Devel::REPL->new;
+ $repl->load_plugin($_) for qw(History LexEnv);
+ $repl->run
+
+Alternatively, use the 're.pl' script installed with the distribution
+
+=head1 AUTHOR
+
+Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>)
+
+=head1 LICENSE
+
+This library is free software under the same terms as perl itself
+
+=cut
+
1;
Added: trunk/Devel-REPL/script/re.pl
===================================================================
--- trunk/Devel-REPL/script/re.pl (rev 0)
+++ trunk/Devel-REPL/script/re.pl 2007-05-28 23:20:56 UTC (rev 3391)
@@ -0,0 +1,10 @@
+#!/usr/bin/env perl
+
+use lib 'lib';
+use Devel::REPL::Script 'run';
+
+#my $repl = Devel::REPL->new;
+
+#$repl->load_plugin('History');
+#$repl->load_plugin('LexEnv');
+#$repl->run;
Property changes on: trunk/Devel-REPL/script/re.pl
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ text/script
More information about the Bast-commits
mailing list