File Coverage

blib/lib/Acme/HidamariSketch.pm
Criterion Covered Total %
statement 42 43 97.6
branch 7 8 87.5
condition n/a
subroutine 9 9 100.0
pod 4 4 100.0
total 62 64 96.8


line stmt bran cond sub pod time code
1             package Acme::HidamariSketch;
2 5     5   208612 use 5.008005;
  5         47  
  5         207  
3 5     5   30 use strict;
  5         8  
  5         210  
4 5     5   44 use warnings;
  5         11  
  5         260  
5 5     5   31 use utf8;
  5         10  
  5         120  
6              
7             our $VERSION = "0.05";
8              
9              
10             my @characters = qw(
11             Yuno
12             Miyako
13             Hiro
14             Sae
15             Nori
16             Nazuna
17             Matsuri
18             Riri
19             Misato
20             );
21              
22             my %year = (
23             before => 0, # 前年 (ゆの入学前)
24             first => 1, # 1年目 (ゆの入学)
25             second => 2, # 2年目
26             third => 3, # 3年目 (現在)
27             );
28              
29             my $SINGLETON;
30              
31              
32             sub new {
33 4 50   4 1 3019 if ($SINGLETON) {
34 0         0 return $SINGLETON;
35             }
36             else {
37 4         13 my $class = shift;
38              
39 4         29 my $SINGLETON = bless {characters => [], year => 'third'}, $class;
40              
41 4         22 $SINGLETON->_init;
42              
43 4         18 return $SINGLETON;
44             }
45             }
46              
47             sub characters {
48 1     1 1 7 my ($self, %options) = @_;
49              
50 1         1 return @{$self->{characters}};
  1         5  
51             }
52              
53             sub apartment {
54 4     4 1 17 my $self = shift;
55              
56 4         8 my $module_name = 'Acme::HidamariSketch::Apartment';
57              
58 4         252 eval "require $module_name";
59              
60 4         17 my @tenant;
61 4         9 for my $character (@{$self->{characters}}) {
  4         17  
62 36 100       133 if (defined $character->{room_number}->{$self->year}) {
63 20         37 push @tenant, $character;
64             }
65             }
66              
67 4         40 return $module_name->new({
68             tenants => [@tenant],
69             year => $self->{year},
70             });
71             }
72              
73             sub year {
74 38     38 1 53 my $self = shift;
75 38 100       81 if (@_) {
76 2         5 my $year = shift;
77 2         9 for my $key (keys %year) {
78 8 100       24 $self->{year} = $year if ($key eq $year);
79             }
80             }
81 38         136 return $self->{year};
82             }
83              
84             sub _init {
85 4     4   8 my $self = shift;
86              
87 4         14 for my $character (@characters) {
88 36         78 my $module_name = 'Acme::HidamariSketch::' . $character;
89              
90 36         2415 eval "require $module_name;";
91 36         125 push @{$self->{characters}}, $module_name->new;
  36         324  
92             }
93              
94 4         10 return 1;
95             }
96              
97             1;
98             __END__