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