Commit | Line | Data |
4d33251a |
1 | package Devel::REPL::Profile; |
9d2a4940 |
2 | # ABSTRACT: Code to execute when re.pl starts |
4d33251a |
3 | |
77327851 |
4 | our $VERSION = '1.003030'; |
54beb05d |
5 | |
4d33251a |
6 | use Moose::Role; |
4d33251a |
7 | requires 'apply_profile'; |
1d6c2dbc |
8 | use namespace::autoclean; |
4d33251a |
9 | |
9d2a4940 |
10 | 1; |
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 | |
33 | For particular projects you might well end up running the same commands each |
34 | time the REPL shell starts up - loading Perl modules, setting configuration, |
35 | and so on. |
36 | |
37 | A mechanism called I<profiles> exists to let you package and distribute these |
38 | start-up scripts, as Perl modules. |
39 | |
40 | =head1 USAGE |
41 | |
42 | Quite simply, follow the L</"SYNOPSIS"> section above to create a boilerplate |
43 | profile module. Within the C<apply_profile> method, the C<$repl> variable can |
44 | be used to run any commands as the user would, within the context of their |
45 | running C<Devel::REPL> shell instance. |
46 | |
47 | For 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 | |
54 | As you can see, the C<eval> method is used to run any code. The user won't see |
55 | any output from that, and the code can "safely" die without destroying the |
56 | REPL shell. The return value of C<eval> will be the return value of the code |
57 | you gave, or else if it died then a C<Devel::REPL::Error> object is returned. |
58 | |
59 | If you want to load a C<Devel::REPL> plugin, then use the following method: |
60 | |
61 | $repl->load_plugin('Timing'); |
62 | |
63 | The C<load_plugin> and C<eval> methods should cover most of what you would |
64 | want to do before the user has access to the shell. Remember that plugin |
65 | features are immediately available, so you can load for example the C<LexEnv> |
66 | plugin, and then declare C<my> variables which the user will have access to. |
67 | |
68 | =head2 Selecting a Profile |
69 | |
70 | To run the shell with a particular profile, use the following command: |
71 | |
72 | system$ re.pl --profile MyProject |
73 | |
cdbe3d31 |
74 | Alternatively, you can set the environment variable C<DEVEL_REPL_PROFILE> to |
75 | MyProject. |
76 | |
a4dd2d89 |
77 | When the profile name is unqualified, as in the above example, the profile is |
78 | assumed to be in the C<Devel::REPL::Profile::> namespace. Otherwise if you |
79 | pass something which contains the C<::> character sequence, it will be loaded |
80 | as-is. |
81 | |
82 | =head1 AUTHOR |
83 | |
84 | Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>) |
85 | |
a4dd2d89 |
86 | =cut |