From: matthewt Date: Mon, 28 May 2007 23:20:56 +0000 (+0000) Subject: basic packaging code X-Git-Tag: v1.003015~166 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=commitdiff_plain;h=59aedffcb81ce6f4b2c477673fb58aee32138d7e;hp=a2532f4673020dcde0245441fd98d51a0692bbd1 basic packaging code git-svn-id: http://dev.catalyst.perl.org/repos/bast/trunk/Devel-REPL@3391 bd8105ee-0ff8-0310-8827-fb3f25b6796d --- diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..51f2495 --- /dev/null +++ b/Makefile.PL @@ -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; diff --git a/lib/Devel/REPL.pm b/lib/Devel/REPL.pm index b096f9b..07f3828 100644 --- a/lib/Devel/REPL.pm +++ b/lib/Devel/REPL.pm @@ -3,6 +3,9 @@ package Devel::REPL; 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'; @@ -82,7 +85,30 @@ sub error_return { 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) + +=head1 LICENSE + +This library is free software under the same terms as perl itself + +=cut + 1; diff --git a/lib/Devel/REPL/Script.pm b/lib/Devel/REPL/Script.pm new file mode 100644 index 0000000..dc24a6a --- /dev/null +++ b/lib/Devel/REPL/Script.pm @@ -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 = ; } + 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; diff --git a/script/re.pl b/script/re.pl new file mode 100755 index 0000000..3b8f6e4 --- /dev/null +++ b/script/re.pl @@ -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;