| 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'
MC/DC0%0/1
$bot->vars || 'store.yaml'
$bot->vars
Truth table0%0/2
A
A= $bot->vars
| |||||||||||||
| 23 | |||||||||||||
| 24 | 0 | eval { | |||||||||||
| 25 | 0 | ▶ | unless ( -f $self->{file} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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__ | ||||||||||||