| 1 | package Bot::Cobalt::Conf::File::PerPlugin; | ||
| 2 | $Bot::Cobalt::Conf::File::PerPlugin::VERSION = '0.021001'; | ||
| 3 | ## This is in File:: but NOT a subclass of File.pm | ||
| 4 | |||
| 5 | 1 | ▶ | use strictures 2; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | ▶ | use Bot::Cobalt::Common ':types'; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 9 | |||
| 10 | use Scalar::Util 'blessed'; | ||
| 11 | |||
| 12 | use Types::Path::Tiny -types; | ||
| 13 | |||
| 14 | use Moo; | ||
| 15 | with 'Bot::Cobalt::Conf::Role::Reader'; | ||
| 16 | |||
| 17 | |||
| 18 | has module => ( | ||
| 19 | required => 1, | ||
| 20 | is => 'rwp', | ||
| 21 | isa => Str, | ||
| 22 | ); | ||
| 23 | |||
| 24 | has extra_opts => ( | ||
| 25 | ## Overrides the plugin-specific cfg. | ||
| 26 | lazy => 1, | ||
| 27 | is => 'ro', | ||
| 28 | isa => HashRef, | ||
| 29 | predicate => 'has_extra_opts', | ||
| 30 | writer => 'set_extra_opts', | ||
| 31 | ); | ||
| 32 | |||
| 33 | has priority => ( | ||
| 34 | lazy => 1, | ||
| 35 | is => 'ro', | ||
| 36 | isa => Num, | ||
| 37 | writer => 'set_priority', | ||
| 38 | predicate => 'has_priority', | ||
| 39 | default => sub { 1 }, | ||
| 40 | ); | ||
| 41 | |||
| 42 | has config_file => ( | ||
| 43 | lazy => 1, | ||
| 44 | is => 'ro', | ||
| 45 | isa => Path, | ||
| 46 | coerce => 1, | ||
| 47 | writer => 'set_config_file', | ||
| 48 | predicate => 'has_config_file', | ||
| 49 | ); | ||
| 50 | |||
| 51 | has autoload => ( | ||
| 52 | lazy => 1, | ||
| 53 | is => 'ro', | ||
| 54 | isa => Bool, | ||
| 55 | default => sub { 1 }, | ||
| 56 | ); | ||
| 57 | |||
| 58 | has opts => ( | ||
| 59 | lazy => 1, | ||
| 60 | is => 'rwp', | ||
| 61 | isa => HashRef, | ||
| 62 | builder => '_build_opts', | ||
| 63 | ); | ||
| 64 | |||
| 65 | sub _build_opts { | ||
| 66 | my ($self) = @_; | ||
| 67 | |||
| 68 | ## - readfile() our config_file if we have one | ||
| 69 | ## - override with extra_opts if we have any | ||
| 70 | |||
| 71 | my $opts_hash; | ||
| 72 | |||
| 73 | if ( $self->has_config_file ) { | ||
| 74 | $opts_hash = $self->readfile( $self->config_file ) | ||
| 75 | } | ||
| 76 | |||
| 77 | if ( $self->has_extra_opts ) { | ||
| 78 | ## 'Opts' directive in plugins.conf was passed in | ||
| 79 | $opts_hash->{$_} = $self->extra_opts->{$_} | ||
| 80 | for keys %{ $self->extra_opts }; | ||
| 81 | } | ||
| 82 | |||
| 83 | $opts_hash // {} | ||
| 84 | } | ||
| 85 | |||
| 86 | sub reload_conf { | ||
| 87 | my ($self) = @_; | ||
| 88 | $self->_set_opts( $self->_build_opts ) | ||
| 89 | } | ||
| 90 | |||
| 91 | 1; | ||
| 92 | __END__ | ||