HidamariSketch.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 97.0% 66 / 68 CC 8 SCAR 8.7
CC
8
Cov
96%
year
4.0
apartment
3.0
new
2.1
CRAP 2.4
« HidamariSketch/Apartment.pm ↑ Summary HidamariSketch/Base.pm »
1 package Acme::HidamariSketch;
2 5 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 our $VERSION = "0.05";
8  
9  
10 5 my @characters = qw(
11 Yuno
12 Miyako
13 Hiro
14 Sae
15 Nori
16 Nazuna
17 Matsuri
18 Riri
19 Misato
20 );
21  
22 5 my %year = (
23 before => 0, # 前年 (ゆの入学前)
24 first => 1, # 1年目 (ゆの入学)
25 second => 2, # 2年目
26 third => 3, # 3年目 (現在)
27 );
28  
29 5 my $SINGLETON;
30  
31  
32 4 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
33 4 ▶ if ($SINGLETON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SINGLETON) { } 0 4 4
34 0 return $SINGLETON;
35 }
36 else {
37 4 my $class = shift;
38  
39 4 my $SINGLETON = bless {characters => [], year => 'third'}, $class;
40  
41 4 $SINGLETON->_init;
42  
43 4 return $SINGLETON;
44 }
45 }
46  
47 1 ▶sub characters {
Subroutine characters: called CC=1 SCAR=0.0
Pod documented
48 1 my ($self, %options) = @_;
49  
50 1 return @{$self->{characters}};
51 }
52  
53 4 ▶sub apartment {
Subroutine apartment: called CC=3 SCAR=11.0
Pod documented
54 4 my $self = shift;
55  
56 4 my $module_name = 'Acme::HidamariSketch::Apartment';
57  
58 4 eval "require $module_name";
59  
60 4 my @tenant;
61 4 for my $character (@{$self->{characters}}) {
62 36 ▶ if (defined $character->{room_number}->{$self->year}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $character->{"room_number"}{$self->year}) 20 16 36
63 20 push @tenant, $character;
64 }
65 }
66  
67 return $module_name->new({
68 tenants => [@tenant],
69 year => $self->{year},
70 4 });
71 }
72  
73 38 ▶sub year {
Subroutine year: called CC=4 SCAR=13.9
Pod documented
74 38 my $self = shift;
75 38 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 36 38
76 2 my $year = shift;
77 2 for my $key (keys %year) {
78 8 ▶ $self->{year} = $year if ($key eq $year);
Branch: 1 branch
BranchTrueFalseTotal
if $key eq $year 2 6 8
79 }
80 }
81 38 return $self->{year};
82 }
83  
84 4 ▶sub _init {
Subroutine _init: called CC=2 SCAR=6.9
85 4 my $self = shift;
86  
87 4 for my $character (@characters) {
88 36 my $module_name = 'Acme::HidamariSketch::' . $character;
89  
90 36 eval "require $module_name;";
91 36 push @{$self->{characters}}, $module_name->new;
92 }
93  
94 4 return 1;
95 }
96  
97 5 1;
98 __END__
« HidamariSketch/Apartment.pm ↑ Summary HidamariSketch/Base.pm »