| 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 | local $ENV{GITALIST_REPO_DIR} = $self->repo_dir; | ||
| 20 | $self->$orig(@_); | ||
| 21 | }; | ||
| 22 | |||
| 23 | 1; | ||
| 24 | |||
| 25 | =head1 NAME | ||
| 26 | |||
| 27 | Gitalist::ScriptRole - Role for Gitalist scripts. | ||
| 28 | |||
| 29 | =head1 DESCRIPTION | ||
| 30 | |||
| 31 | Wraps the run method in Catalyst scripts to apply the C<< --repo_dir >> | ||
| 32 | option. | ||
| 33 | |||
| 34 | =head1 AUTHORS | ||
| 35 | |||
| 36 | See L<Gitalist> for authors. | ||
| 37 | |||
| 38 | =head1 LICENSE | ||
| 39 | |||
| 40 | See L<Gitalist> for the license. | ||
| 41 | |||
| 42 | =cut |