increment $VERSION after 1.003029 release
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Profile.pm
1 package Devel::REPL::Profile;
2 # ABSTRACT: Code to execute when re.pl starts
3
4 our $VERSION = '1.003030';
5
6 use Moose::Role;
7 requires 'apply_profile';
8 use namespace::autoclean;
9
10 1;
11 __END__
12
13 =pod
14
15 =head1 SYNOPSIS
16
17  package Devel::REPL::Profile::MyProject;
18
19  use Moose;
20  use namespace::autoclean;
21
22  with 'Devel::REPL::Profile';
23
24  sub apply_profile {
25      my ($self, $repl) = @_;
26      # do something here
27  }
28
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
74 Alternatively, you can set the environment variable C<DEVEL_REPL_PROFILE> to
75 MyProject.
76
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
86 =cut