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