| 1 | package Bot::Cobalt::Conf::File; | ||||||||||
| 2 | 5 | $Bot::Cobalt::Conf::File::VERSION = '0.021003'; | |||||||||
| 3 | 5 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use strictures 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 5 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 5 | ▶ | use Bot::Cobalt::Common ':types'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | ▶ | use Bot::Cobalt::Serializer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 5 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 5 | ▶ | use Types::Path::Tiny -types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 5 | ▶ | use List::Objects::WithUtils; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 5 | ▶ | use List::Objects::Types -types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 5 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 5 | with 'Bot::Cobalt::Conf::Role::Reader'; | |||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | 5 | has cfg_path => ( | |||||||||
| 22 | required => 1, | ||||||||||
| 23 | is => 'rwp', | ||||||||||
| 24 | isa => Path, | ||||||||||
| 25 | coerce => 1, | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | 5 | has cfg_as_hash => ( | |||||||||
| 29 | lazy => 1, | ||||||||||
| 30 | is => 'rwp', | ||||||||||
| 31 | isa => HashObj, | ||||||||||
| 32 | coerce => 1, | ||||||||||
| 33 | builder => '_build_cfg_hash', | ||||||||||
| 34 | ); | ||||||||||
| 35 | |||||||||||
| 36 | has debug => ( | ||||||||||
| 37 | is => 'rw', | ||||||||||
| 38 | isa => Bool, | ||||||||||
| 39 | 0 | ▶ | builder => sub { 0 }, | ||||||||
|
Subroutine
_build_debug: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 40 | 5 | ); | |||||||||
| 41 | |||||||||||
| 42 | 7 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 43 | 7 | my ($self) = @_; | |||||||||
| 44 | 7 | $self->cfg_as_hash | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 8 | ▶ | sub _build_cfg_hash { | ||||||||
|
Subroutine
_build_cfg_hash: called CC=3 SCAR=11.3
| |||||||||||
| 48 | 8 | my ($self) = @_; | |||||||||
| 49 | |||||||||||
| 50 | 8 | ▶ | if ($self->debug) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 1 | warn | |||||||||
| 52 | ref $self, " (debug) reading cfg_as_hash from ", $self->cfg_path, "\n" | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 8 | my $cfg = $self->readfile( $self->cfg_path ); | |||||||||
| 56 | |||||||||||
| 57 | 8 | ▶ | my $err; try { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 58 | 8 | $self->validate($cfg) | |||||||||
| 59 | 0 | ▶ | } catch { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.0
| |||||||||||
| 60 | 0 | $err = $_; | |||||||||
| 61 | undef | ||||||||||
| 62 | 0 | ▶ | } or croak "Conf validation failed for ". $self->cfg_path .": $err"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | |||||||||||
| 64 | 8 | $cfg | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 1 | ▶ | sub rehash { | ||||||||
|
Subroutine
rehash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 68 | 1 | my ($self) = @_; | |||||||||
| 69 | |||||||||||
| 70 | 1 | $self->_set_cfg_as_hash( $self->_build_cfg_hash ) | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 2 | ▶ | sub validate { | ||||||||
|
Subroutine
validate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 74 | 2 | my ($self, $cfg) = @_; | |||||||||
| 75 | |||||||||||
| 76 | 2 | 1 | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 5 | 1; | |||||||||
| 80 | __END__ | ||||||||||