IRC/Store.pm

filter: Statementstmt 43.3% 13 / 30 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 50.0% 4 / 8 Podpod 50.0% 2 / 4 totaltotal 38.7% 19 / 49 CC 4 SCAR 20.9
CC
4
Cov
36%
new
20.0
get
2.0
set
2.0
CRAP 8.1
« IRC/Join.pm ↑ Summary IRC/Functions.pm »
1 package Bot::IRC::Store;
2 # ABSTRACT: Bot::IRC persistent data storage with YAML
3  
4 12 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use exact;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 ▶use YAML::XS qw( LoadFile DumpFile );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 our $VERSION = '1.49'; # VERSION
10  
11 4 ▶sub init {
Subroutine init: called CC=1 SCAR=0.2
Pod undocumented
12 4 my ($bot) = @_;
13 4 my $obj = __PACKAGE__->new($bot);
14  
15 0 ▶ $bot->subs( 'store' => sub { return $obj } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
16 }
17  
18 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
19 0 my ( $class, $bot ) = @_;
20 0 my $self = bless( {}, $class );
21  
22 0 ▶ $self->{file} = $bot->vars || 'store.yaml';
Condition0%0/2
$bot->vars || 'store.yaml'
l!l
00
MC/DC0%0/1
$bot->vars || 'store.yaml'
$bot->vars
Truth table0%0/2
A
A= $bot->vars
Aresult
11
00
23  
24 0 eval {
25 0 ▶ unless ( -f $self->{file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $self->{'file'}) { } 0 0 0
26 0 DumpFile( $self->{file}, {} );
27 }
28 else {
29 0 LoadFile( $self->{file} );
30 }
31 };
32 0 ▶ die qq{Unable to use "$self->{file}" for YAML storage in the Bot::IRC::Store plugin\n} if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
33  
34 0 return $self;
35 }
36  
37 0 ▶sub get {
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
38 0 my ( $self, $key ) = @_;
39 0 return LoadFile( $self->{file} )->{ ( caller() )[0] }{$key};
40 }
41  
42 0 ▶sub set {
Subroutine set: not called CC=1 SCAR=6.9
Pod documented
43 0 my ( $self, $key, $value ) = @_;
44  
45 0 my $data = LoadFile( $self->{file} );
46 0 $data->{ ( caller() )[0] }{$key} = $value;
47  
48 0 DumpFile( $self->{file}, $data );
49 0 return $self;
50 }
51  
52 12 1;
53  
54 __END__
« IRC/Join.pm ↑ Summary IRC/Functions.pm »