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