Achievements/Achievement.pm

filter: Statementstmt 50.7% 32 / 63 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 47.0% 8 / 17 Podpod 16.6% 1 / 6 totaltotal 42.7% 41 / 96 CC 7 SCAR 14.7
CC
7
Cov
44%
pack
12.0
get_config_from_file
6.0
storage_file
6.0
CRAP 4.3
« Achievements.pm ↑ Summary Achievements/Command.pm »
1 package Perl::Achievements::Achievement;
2 6 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 $Perl::Achievements::Achievement::AUTHORITY = 'cpan:YANICK';
4 }
5 {
6 6 $Perl::Achievements::Achievement::VERSION = '0.4.0';
7 }
8 # ABSTRACT: base role for achievements
9  
10  
11 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 6 ▶no warnings qw/ uninitialized /;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 ▶use MooseX::SemiAffordanceAccessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 6 ▶use YAML::Any qw/ LoadFile DumpFile /;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶use DateTime::Functions qw/ now /;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 6 with 'MooseX::ConfigFromFile';
24  
25 6 requires qw/ scan /;
26  
27  
28 6 has 'app' => (
29 required => 1,
30 is => 'ro',
31 handles => [ qw/ ppi log log_debug dry_run / ],
32 );
33  
34  
35  
36  
37 6 has level => (
38 traits => [ 'Perl::Achievements::Role::ConfigItem', 'Counter' ],
39 isa => 'Num',
40 is => 'rw',
41 default => 0,
42 handles => {
43 inc_level => 'inc'
44 },
45 );
46  
47 0 ▶sub get_config_from_file {
Subroutine get_config_from_file: not called CC=2 SCAR=17.9
Pod undocumented
48 0 my ( undef, $file ) = @_;
49  
50 0 ▶ return -f $file ? LoadFile( $file ) : {};
Branch: 1 branch
BranchTrueFalseTotal
-f $file ? : 0 0 0
51 }
52  
53 0 ▶sub storage_file {
Subroutine storage_file: not called CC=2 SCAR=17.9
Pod undocumented
54 0 my $class = shift;
55  
56 # if object, turn to class name
57 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
58  
59 0 $class =~ s/^Perl::Achievements::Achievement:://;
60 0 $class =~ s/::/__/g;
61 0 $class .= '.yaml';
62  
63 0 return $class;
64 }
65  
66 0 ▶sub load_or_new {
Subroutine load_or_new: not called CC=1 SCAR=6.9
Pod undocumented
67 0 my ( $class, %args ) = @_;
68  
69 0 my $file = $args{app}->rc_file_path( 'achievements', $class->storage_file );
70  
71 0 return $class->new_with_config( configfile => $file, %args );
72 }
73  
74  
75 0 ▶sub unlock {
Subroutine unlock: not called CC=1 SCAR=6.9
Pod documented
76 0 my ($self, $details ) = @_;
77  
78 0 $self->app->unlock_achievement(
79 achievement => ref($self),
80 timestamp => ''.now(),
81 ( level => $self->level ) x ( $self->level > 0 ) ,
82 ( details => $details ) x !!$details,
83 );
84 }
85  
86 0 ▶before unlock => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
87 0 my $self = shift;
88  
89 0 ▶ $self->set_level(0) unless defined $self->level;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->level 0 0 0
90 6 };
91  
92 0 ▶before scan => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
93 0 my $self = shift;
94 0 $self->log_debug( "scanning for achievement " . ref $self );
95 6 };
96  
97 0 ▶after scan => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
98 0 my $self = shift;
99  
100 0 $self->log_debug( 'storing state of ' . ref $self );
101  
102 0 ▶ $self->store( "".$self->app->rc_file_path(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dry_run 0 0 0
103 'achievements', $self->storage_file ) ) unless $self->dry_run;
104 6 };
105  
106 0 ▶sub pack {
Subroutine pack: not called CC=3 SCAR=24.8
Pod undocumented
107 0 my $self = shift;
108  
109 0 my %data;
110  
111 0 for my $attr ( map { $self->meta->get_attribute($_) }
112 $self->meta->get_attribute_list ) {
113 0 ▶ next unless $attr->does('Perl::Achievements::Role::ConfigItem');
Branch: 1 branch
BranchTrueFalseTotal
unless $attr->does("Perl::Achievements::Role::ConfigItem") 0 0 0
114  
115 0 my $name = $attr->name;
116 0 $data{$name} = $self->$name;
117 }
118  
119 0 return %data;
120 }
121  
122 0 ▶sub store {
Subroutine store: not called CC=1 SCAR=6.9
Pod undocumented
123 0 my $self = shift;
124  
125 0 my %data = $self->pack;
126 0 DumpFile( shift, \%data );
127 }
128  
129 6 1;
130  
131 __END__
« Achievements.pm ↑ Summary Achievements/Command.pm »