73e31b3810709ea3b75e76d9952935da5c24c9fb
[catagits/Gitalist.git] / lib / Gitalist / TraitFor / Script.pm
1 package Gitalist::TraitFor::Script;
2 use Moose::Role;
3 use MooseX::Types::Moose qw/ Undef /;
4 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
5 use namespace::autoclean;
6
7 has repo_dir => (
8     isa => Undef | NonEmptySimpleStr,
9     is => 'ro',
10     default => sub {
11         return unless exists $ENV{GITALIST_REPO_DIR};
12         $ENV{GITALIST_REPO_DIR};
13     },
14 );
15
16 around run => sub {
17     my $orig = shift;
18     my $self = shift;
19     warn("Script repo dir" . $self->repo_dir);
20     local $ENV{GITALIST_REPO_DIR} = $self->repo_dir;
21     $self->$orig(@_);
22 };
23
24 1;
25
26 =head1 NAME
27
28 Gitalist::ScriptRole - Role for Gitalist scripts.
29
30 =head1 DESCRIPTION
31
32 Wraps the run method in Catalyst scripts to apply the C<< --repo_dir >>
33 option.
34
35 =head1 AUTHORS
36
37 See L<Gitalist> for authors.
38
39 =head1 LICENSE
40
41 See L<Gitalist> for the license.
42
43 =cut