| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | |||
| 4 | package App::Embra::App::Command; | ||
| 5 | $App::Embra::App::Command::VERSION = '0.001'; # TRIAL | ||
| 6 | # ABSTRACT: base class for embra commands | ||
| 7 | |||
| 8 | use App::Cmd::Setup -command; | ||
| 9 | |||
| 10 | |||
| 11 | sub embra { | ||
| 12 | my ( $self ) = @_; | ||
| 13 | use 5.010; | ||
| 14 | require App::Embra; | ||
| 15 | use feature qw< state >; | ||
| 16 | state $embra = App::Embra->from_config_mvp_sequence( sequence => $self->_create_seq ); | ||
| 17 | } | ||
| 18 | |||
| 19 | sub _die_missing { | ||
| 20 | my ($package) = @_; | ||
| 21 | |||
| 22 | my $bundle = $package =~ /^@/ ? ' bundle' : ''; | ||
| 23 | die <<"END_DIE"; | ||
| 24 | Required plugin$bundle [$package] isn't installed. | ||
| 25 | |||
| 26 | Run 'embra listdeps' to see a list of all required plugins. | ||
| 27 | You can pipe the list to your CPAN client to install or update them: | ||
| 28 | |||
| 29 | embra listdeps | cpanm | ||
| 30 | |||
| 31 | END_DIE | ||
| 32 | } | ||
| 33 | |||
| 34 | # from Dist::Zilla::Dist::Build, where it is known as _load_config | ||
| 35 | |||
| 36 | sub _create_seq { | ||
| 37 | my ( $self ) = @_; | ||
| 38 | require Config::MVP::Reader::Finder; | ||
| 39 | require App::Embra::MVP::Assembler; | ||
| 40 | use Try::Tiny; | ||
| 41 | try { | ||
| 42 | Config::MVP::Reader::Finder->read_config( | ||
| 43 | 'embra', | ||
| 44 | { | ||
| 45 | assembler => App::Embra::MVP::Assembler->new, | ||
| 46 | } | ||
| 47 | ); | ||
| 48 | } catch { | ||
| 49 | my $e = $_; | ||
| 50 | try { | ||
| 51 | for($e) { | ||
| 52 | if($e->ident =~ /package not installed/) { | ||
| 53 | _die_missing($e->package); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | } catch { | ||
| 57 | die $e; | ||
| 58 | }; | ||
| 59 | }; | ||
| 60 | } | ||
| 61 | |||
| 62 | 1; | ||
| 63 | |||
| 64 | __END__ |