| 1 | package Exobrain::Agent::Depends; | ||
| 2 | use Moose::Role; | ||
| 3 | use Method::Signatures; | ||
| 4 | |||
| 5 | # ABSTRACT: Allow agents to declare run-time dependencies | ||
| 6 | our $VERSION = '1.08'; # VERSION | ||
| 7 | |||
| 8 | |||
| 9 | requires 'depends'; | ||
| 10 | |||
| 11 | method check_dependencies() { | ||
| 12 | # Returns true if dependencies could be loaded, false otherwise | ||
| 13 | return eval { $self->load_dependencies; 1; } | ||
| 14 | } | ||
| 15 | |||
| 16 | method load_dependencies() { | ||
| 17 | foreach my $dep ($self->depends) { | ||
| 18 | eval "use Exobrain::$dep; 1;" or die $@; | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | no warnings 'redefine'; | ||
| 23 | |||
| 24 | sub BUILD {}; | ||
| 25 | |||
| 26 | after BUILD => method(...) { | ||
| 27 | $self->load_dependencies; | ||
| 28 | }; | ||
| 29 | |||
| 30 | 1; | ||
| 31 | |||
| 32 | __END__ |