BusyBird/Config.pm

filter: Statementstmt 99.2% 125 / 126 Branchbran 75.0% 21 / 28 Conditioncond 76.1% 16 / 21 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 97.9% 48 / 49 Podpod 100% 3 / 3 totaltotal 91.9% 218 / 237 CC 24 SCAR 10.5
CC
24
Cov
93%
__ANON__
8.4
__ANON__
6.0
get_config
5.0
CRAP 2.8
« BusyBird/Main/PSGI/View.pm ↑ Summary BusyBird/Main/PSGI.pm »
1 package BusyBird::Config;
2 11 ▶use v5.8.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use BusyBird::Log qw(bblog);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use BusyBird::SafeData qw(safed);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use BusyBird::Util qw(config_file_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use URI::Escape qw(uri_escape);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use BusyBird::StatusStorage::SQLite;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use File::ShareDir ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 11 my %_DEFAULTS = ();
16  
17 $_DEFAULTS{timeline} = {
18 3 ▶ time_zone => sub { "local" },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 1 ▶ time_format => sub { '%x (%a) %X %Z' },
Subroutine __ANON__: called CC=1 SCAR=0.0
20 1 ▶ time_locale => sub { $ENV{LC_TIME} or "C" },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"LC_TIME"} or "C" 0 1 1
21 6 ▶ post_button_url => sub { "https://twitter.com/intent/tweet" },
Subroutine __ANON__: called CC=1 SCAR=0.0
22  
23 4 ▶ status_permalink_builder => sub { return sub {
Subroutine __ANON__: called CC=1 SCAR=0.1
Subroutine __ANON__: called CC=8 SCAR=21.2
24 30 my ($status) = @_;
25 30 my $ss = safed($status);
26 30 my $permalink_in_status = $ss->val(qw(busybird status_permalink));
27 30 ▶ return $permalink_in_status if defined $permalink_in_status;
Branch: 1 branch
BranchTrueFalseTotal
if defined $permalink_in_status 2 28 30
28 28 ▶ my $id = $ss->val(qw(busybird original id))
Condition55%5/9
$ss->val('busybird', 'original', 'id') || $ss->val('busybird', 'original', 'id_str') || $ss->val('id') || $ss->val('id_str')
l!l&&r!l&&!r
2800
$ss->val("busybird", "original", "id") or $ss->val("busybird", "original", "id_str") or $ss->val("id")
l!l&&r!l&&!r
1270
$ss->val("busybird", "original", "id") or $ss->val("busybird", "original", "id_str")
l!l&&r!l&&!r
1027
MC/DC0%0/4
$ss->val('busybird', 'original', 'id') || $ss->val('busybird', 'original', 'id_str') || $ss->val('id') || $ss->val('id_str')
$ss->val("busybird", "original", "id") $ss->val("busybird", "original", "id_str") $ss->val("id") $ss->val('id_str')
Truth table40%2/5
A or B or C || D
A= $ss->val("busybird", "original", "id")B= $ss->val("busybird", "original", "id_str")C= $ss->val("id")D= $ss->val('id_str')
ABCDresult
1XXX1
01XX1
001X1
00011
00000
29 || $ss->val(qw(busybird original id_str))
30 || $ss->val("id")
31 || $ss->val("id_str");
32 28 my $username = $ss->val(qw(user screen_name));
33 28 ▶ if(defined($id) && defined($username) && $id =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id and defined $username and $id =~ /^\d+$/) 2 26 28
Condition83%5/6
defined $id and defined $username and $id =~ /^\d+$/
!ll&&!rl&&r
2512
defined $id and defined $username
!ll&&!rl&&r
0253
MC/DC66%2/3
defined $id and defined $username and $id =~ /^\d+$/
defined $id defined $username $id =~ /^\d+$/
Truth table75%3/4
A and B and C
A= defined $idB= defined $usernameC= $id =~ /^\d+$/
ABCresult
0XX0
10X0
1100
1111
34 2 return qq{https://twitter.com/$username/status/$id};
35 }
36 26 return undef;
37 4 } },
38  
39 1 ▶ urls_entity_url_builder => sub { sub { my ($text, $entity) = @_; return $entity->{url} }},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
40 1 ▶ urls_entity_text_builder => sub { sub { my ($text, $entity) = @_; return $entity->{display_url} }},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
41
42 1 ▶ media_entity_url_builder => sub { sub { my ($text, $entity) = @_; return $entity->{url} } },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
43 1 ▶ media_entity_text_builder => sub { sub { my ($text, $entity) = @_; return $entity->{display_url} }},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
44
45 1 ▶ user_mentions_entity_url_builder => sub { sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=2 SCAR=7.0
46 1 my ($text, $entity, $status) = @_;
47 1 my $screen_name = $entity->{screen_name};
48 1 ▶ $screen_name = "" if not defined $screen_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $screen_name 0 1 1
49 1 return qq{https://twitter.com/$screen_name};
50 1 }},
51 1 ▶ user_mentions_entity_text_builder => sub { sub { my $text = shift; return $text }},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
52
53 1 ▶ hashtags_entity_url_builder => sub { sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
54 4 my ($text, $entity, $status) = @_;
55 4 my $query_hashtag = uri_escape('#' . Encode::encode('utf8', $entity->{text}));
56 4 return qq{https://twitter.com/search?q=$query_hashtag&src=hash};
57 1 }},
58 1 ▶ hashtags_entity_text_builder => sub { sub { my $text = shift; return $text }},
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
59
60 7 ▶ timeline_web_notifications => sub { 'simple' },
Subroutine __ANON__: called CC=1 SCAR=0.0
61 3 ▶ hidden => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
62  
63 5 ▶ attached_image_urls_builder => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
64 30 ▶ return sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
65 30 my ($status) = @_;
66 30 tie my %url_set, "Tie::IxHash";
67 30 my $ss = safed($status);
68 30 my @entities = map { $ss->array($_, "media") } qw(entities extended_entities);
69 30 foreach my $entity (@entities) {
70 14 my $sentity = safed($entity);
71 14 my $url = $sentity->val("media_url");
72 14 my $type = $sentity->val("type");
73 14 ▶ if(defined($url) && (!defined($type) || lc($type) eq "photo")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url and !defined($type) || lc $type eq "photo") 12 2 14
Condition100%6/6
defined $url and !defined($type) || lc $type eq "photo"
!ll&&!rl&&r
1112
not defined $type or lc $type eq "photo"
l!l&&r!l&&!r
1111
MC/DC100%3/3
defined $url and !defined($type) || lc $type eq "photo"
defined $url not defined $type lc $type eq "photo"
Truth table100%4/4
A and not(B) or C
A= defined $urlB= not defined $typeC= lc $type eq "photo"
ABCresult
0XX0
1000
11X1
1011
74 12 ▶ $url_set{$url} = 1 if defined $url;
Branch: 1 branch
BranchTrueFalseTotal
if defined $url 12 0 12
75 }
76 }
77 30 return keys %url_set;
78 5 };
79 },
80 6 ▶ attached_image_max_height => sub { 360 },
Subroutine __ANON__: called CC=1 SCAR=0.0
81 6 ▶ attached_image_show_default => sub { "hidden" },
Subroutine __ANON__: called CC=1 SCAR=0.0
82 7 ▶ acked_statuses_load_count => sub { 20 },
Subroutine __ANON__: called CC=1 SCAR=0.0
83 7 ▶ default_level_threshold => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
84 11 };
85  
86 $_DEFAULTS{global} = {
87 11 %{$_DEFAULTS{timeline}},
88  
89 0 ▶ default_status_storage => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 0 BusyBird::StatusStorage::SQLite->new(path => config_file_path("statuses.sqlite3"));
91 },
92
93 48 ▶ sharedir_path => sub { File::ShareDir::dist_dir("BusyBird") },
Subroutine __ANON__: called CC=1 SCAR=0.0
94 3 ▶ timeline_list_pager_entry_max => sub { 7 },
Subroutine __ANON__: called CC=1 SCAR=0.0
95 1 ▶ timeline_list_per_page => sub { 30 },
Subroutine __ANON__: called CC=1 SCAR=0.0
96 11 };
97  
98 292 ▶sub new {
Subroutine new: called CC=4 SCAR=14.2
Pod documented
99 292 my ($class, %args) = @_;
100 292 my $type = $args{type};
101 292 ▶ croak "type parameter is mandatory" if not defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 292 292
102 292 my $default_generators = $_DEFAULTS{$type};
103 292 ▶ croak "Unknown config type: $type" if not defined $default_generators;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $default_generators 0 292 292
104 292 ▶ croak "with_default parameter is mandatory" if not defined $args{with_default};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"with_default"} 0 292 292
105 my $self = bless {
106 default_generators => $default_generators,
107 with_default => $args{with_default},
108 292 config => {},
109 }, $class;
110 292 return $self;
111 }
112  
113 864 ▶sub get_config {
Subroutine get_config: called CC=5 SCAR=16.1
Pod documented
114 864 my ($self, $key) = @_;
115 864 ▶ croak "key parameter is mandatory" if not defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 864 864
116 864 ▶ return $self->{config}{$key} if exists $self->{config}{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$self{"config"}{$key} 449 415 864
117 415 ▶ return undef if !$self->{with_default};
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{"with_default"} 297 118 415
118
119 118 my $gen = $self->{default_generators}{$key};
120 118 ▶ return undef if not defined $gen;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gen 2 116 118
121 116 my $value = $gen->();
122 116 $self->set_config($key, $value);
123 116 return $value;
124 }
125  
126 204 ▶sub set_config {
Subroutine set_config: called CC=3 SCAR=11.0
Pod documented
127 204 my ($self, %configs) = @_;
128 204 foreach my $key (keys %configs) {
129 212 ▶ if(!exists($self->{default_generators}{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$self{"default_generators"}{$key}) 9 203 212
130 9 bblog("warn", "Unknown config parameter: $key");
131 }
132 212 $self->{config}{$key} = $configs{$key};
133 }
134 }
135  
136 11 1;
137 __END__
« BusyBird/Main/PSGI/View.pm ↑ Summary BusyBird/Main/PSGI.pm »