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