File Coverage

blib/lib/App/Slackeria/Config.pm
Criterion Covered Total %
statement 18 45 40.0
branch 0 8 0.0
condition 0 5 0.0
subroutine 6 11 54.5
pod 5 5 100.0
total 29 74 39.1


line stmt bran cond sub pod time code
1             package App::Slackeria::Config;
2              
3 1     1   188244 use strict;
  1         10  
  1         245  
4 1     1   27 use warnings;
  1         2  
  1         391  
5 1     1   190 use 5.010;
  1         5  
  1         48  
6              
7 1     1   1429 use Config::Tiny;
  1         2044  
  1         216  
8 1     1   43 use Carp;
  1         2  
  1         278  
9 1     1   1356 use File::BaseDir qw(config_files);
  1         2189  
  1         805  
10              
11             our $VERSION = '0.12';
12              
13             sub new {
14 0     0 1   my ($obj) = @_;
15              
16 0           my $ref = {};
17              
18 0           return bless( $ref, $obj );
19             }
20              
21             sub get {
22 0     0 1   my ( $self, $name, $section ) = @_;
23 0           $self->load($name);
24              
25 0 0         if ( $name ne 'config' ) {
26 0   0       $self->{file}->{$name}->{$section}->{name} //= $name;
27             }
28              
29 0   0       return $self->{file}->{$name}->{$section} // {};
30             }
31              
32             sub load {
33 0     0 1   my ( $self, $name ) = @_;
34 0           my $file = config_files("slackeria/${name}");
35              
36 0 0         if ( defined $self->{file}->{$name} ) {
37 0           return;
38             }
39              
40 0 0         if ($file) {
41 0           $self->{file}->{$name} = Config::Tiny->read($file);
42             }
43             else {
44 0           $self->{file}->{$name} = {};
45             }
46              
47 0 0         if ( $name eq 'config' ) {
48 0           $self->{projects}
49             = [ split( / /, $self->{file}->{$name}->{slackeria}->{projects} ) ];
50 0           delete $self->{file}->{$name}->{slackeria};
51             }
52              
53 0           return;
54             }
55              
56             sub projects {
57 0     0 1   my ($self) = @_;
58              
59 0           $self->load('config');
60              
61 0           return @{ $self->{projects} };
  0            
62             }
63              
64             sub plugins {
65 0     0 1   my ($self) = @_;
66              
67 0           $self->load('config');
68              
69 0           return keys %{ $self->{file}->{config} };
  0            
70             }
71              
72             1;
73              
74             __END__