File Coverage

blib/lib/Wikibase/Cache/Backend/Basic.pm
Criterion Covered Total %
statement 36 40 90.0
branch 2 4 50.0
condition n/a
subroutine 9 10 90.0
pod 0 1 0.0
total 47 55 85.4


line stmt bran cond sub pod time code
1             package Wikibase::Cache::Backend::Basic;
2              
3 4     4   284480 use base qw(Wikibase::Cache::Backend);
  4         37  
  4         2025  
4 4     4   55150 use strict;
  4         8  
  4         77  
5 4     4   20 use warnings;
  4         7  
  4         109  
6              
7 4     4   49 use Class::Utils qw(set_params);
  4         12  
  4         140  
8 4     4   23 use Error::Pure qw(err);
  4         7  
  4         118  
9 4     4   1794 use Text::DSV;
  4         2051  
  4         1128  
10              
11             our $VERSION = 0.02;
12              
13             sub new {
14 2     2 0 161 my ($class, @params) = @_;
15              
16             # Create object.
17 2         7 my $self = bless {}, $class;
18              
19             # Process parameters.
20 2         10 set_params($self, @params);
21              
22 2         23 $self->_load_data;
23              
24 2         9 return $self;
25             }
26              
27             sub _get {
28 2     2   809 my ($self, $type, $key) = @_;
29              
30 2 50       7 if (exists $self->{static}->{$key}) {
31 2 50       5 if (exists $self->{static}->{$key}->{$type}) {
32 2         26 return $self->{static}->{$key}->{$type};
33             } else {
34 0         0 return;
35             }
36             } else {
37 0         0 return;
38             }
39             }
40              
41             sub _load_data {
42 2     2   5 my $self = shift;
43              
44             # Read data.
45 2         3 my $kramerius_data;
46 2         9 my $dsv = Text::DSV->new;
47 2         25 while (my $data = ) {
48 102         153 chomp $data;
49 102         205 my ($qid, $label, $description) = $dsv->parse_line($data);
50 102         1883 $self->{'static'}->{$qid}->{'label'} = $label;
51 102         390 $self->{'static'}->{$qid}->{'description'} = $description;
52             }
53              
54 2         24 return;
55             }
56              
57             sub _save {
58 0     0     my ($self, $type, $key, $value) = @_;
59              
60 0           err __PACKAGE__." doesn't implement save() method.";
61             }
62              
63             1;
64              
65             __DATA__