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