File Coverage

blib/lib/Bot/Cobalt/Conf/File/PerPlugin.pm
Criterion Covered Total %
statement 28 28 100.0
branch 4 4 100.0
condition 1 2 50.0
subroutine 8 8 100.0
pod 0 1 0.0
total 41 43 95.3


line stmt bran cond sub pod time code
1             package Bot::Cobalt::Conf::File::PerPlugin;
2             $Bot::Cobalt::Conf::File::PerPlugin::VERSION = '0.021002';
3             ## This is in File:: but NOT a subclass of File.pm
4              
5 5     5   19 use strictures 2;
  5         24  
  5         159  
6 5     5   652 use Carp;
  5         5  
  5         222  
7              
8 5     5   17 use Bot::Cobalt::Common ':types';
  5         6  
  5         21  
9              
10 5     5   22 use Scalar::Util 'blessed';
  5         5  
  5         202  
11              
12 5     5   358 use Types::Path::Tiny -types;
  5         16890  
  5         33  
13              
14 5     5   3183 use Moo;
  5         5688  
  5         24  
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 4     4   572 my ($self) = @_;
67            
68             ## - readfile() our config_file if we have one
69             ## - override with extra_opts if we have any
70              
71 4         5 my $opts_hash;
72            
73 4 100       12 if ( $self->has_config_file ) {
74 1         4 $opts_hash = $self->readfile( $self->config_file )
75             }
76              
77 4 100       10 if ( $self->has_extra_opts ) {
78             ## 'Opts' directive in plugins.conf was passed in
79             $opts_hash->{$_} = $self->extra_opts->{$_}
80 3         3 for keys %{ $self->extra_opts };
  3         17  
81             }
82              
83             $opts_hash // {}
84 4   50     47 }
85              
86             sub reload_conf {
87 1     1 0 8 my ($self) = @_;
88 1         2 $self->_set_opts( $self->_build_opts )
89             }
90              
91             1;
92             __END__