| 1 | use MooseX::Declare; | ||
| 2 | |||
| 3 | role CatalystX::Declare::Context::AppSetup { | ||
| 4 | |||
| 5 | use MooseX::Types::Moose qw( Bool ); | ||
| 6 | use Carp qw( croak ); | ||
| 7 | |||
| 8 | |||
| 9 | has setup_was_called => ( | ||
| 10 | is => 'rw', | ||
| 11 | isa => Bool, | ||
| 12 | ); | ||
| 13 | |||
| 14 | method add_setup_code_parts (Str $package, ArrayRef $plugins = []) { | ||
| 15 | |||
| 16 | if ($self->setup_was_called) { | ||
| 17 | croak 'call to setup already pushed to cleanup code parts'; | ||
| 18 | } | ||
| 19 | |||
| 20 | $self->add_cleanup_code_parts( | ||
| 21 | sprintf( | ||
| 22 | '%s->setup(qw( %s ))', | ||
| 23 | $package, | ||
| 24 | join(' ', @$plugins), | ||
| 25 | ), | ||
| 26 | '1;', | ||
| 27 | ); | ||
| 28 | $self->setup_was_called(1); | ||
| 29 | } | ||
| 30 | } | ||
| 31 |