increment $VERSION after 1.003028 release
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Profile.pm
CommitLineData
4d33251a 1package Devel::REPL::Profile;
9d2a4940 2# ABSTRACT: Code to execute when re.pl starts
4d33251a 3
c45376f3 4our $VERSION = '1.003029';
54beb05d 5
4d33251a 6use Moose::Role;
4d33251a 7requires 'apply_profile';
1d6c2dbc 8use namespace::autoclean;
4d33251a 9
9d2a4940 101;
11__END__
a4dd2d89 12
9d2a4940 13=pod
a4dd2d89 14
15=head1 SYNOPSIS
16
17 package Devel::REPL::Profile::MyProject;
afc8677b 18
a4dd2d89 19 use Moose;
aa8b7647 20 use namespace::autoclean;
afc8677b 21
a4dd2d89 22 with 'Devel::REPL::Profile';
afc8677b 23
a4dd2d89 24 sub apply_profile {
25 my ($self, $repl) = @_;
26 # do something here
27 }
afc8677b 28
a4dd2d89 29 1;
30
31=head1 DESCRIPTION
32
33For particular projects you might well end up running the same commands each
34time the REPL shell starts up - loading Perl modules, setting configuration,
35and so on.
36
37A mechanism called I<profiles> exists to let you package and distribute these
38start-up scripts, as Perl modules.
39
40=head1 USAGE
41
42Quite simply, follow the L</"SYNOPSIS"> section above to create a boilerplate
43profile module. Within the C<apply_profile> method, the C<$repl> variable can
44be used to run any commands as the user would, within the context of their
45running C<Devel::REPL> shell instance.
46
47For example, to load a module, you might have something like this:
48
49 sub apply_profile {
50 my ($self, $repl) = @_;
51 $repl->eval('use Carp');
52 }
53
54As you can see, the C<eval> method is used to run any code. The user won't see
55any output from that, and the code can "safely" die without destroying the
56REPL shell. The return value of C<eval> will be the return value of the code
57you gave, or else if it died then a C<Devel::REPL::Error> object is returned.
58
59If you want to load a C<Devel::REPL> plugin, then use the following method:
60
61 $repl->load_plugin('Timing');
62
63The C<load_plugin> and C<eval> methods should cover most of what you would
64want to do before the user has access to the shell. Remember that plugin
65features are immediately available, so you can load for example the C<LexEnv>
66plugin, and then declare C<my> variables which the user will have access to.
67
68=head2 Selecting a Profile
69
70To run the shell with a particular profile, use the following command:
71
72 system$ re.pl --profile MyProject
73
cdbe3d31 74Alternatively, you can set the environment variable C<DEVEL_REPL_PROFILE> to
75MyProject.
76
a4dd2d89 77When the profile name is unqualified, as in the above example, the profile is
78assumed to be in the C<Devel::REPL::Profile::> namespace. Otherwise if you
79pass something which contains the C<::> character sequence, it will be loaded
80as-is.
81
82=head1 AUTHOR
83
84Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>)
85
a4dd2d89 86=cut