line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TV::ARIB::ProgramGenre; |
2
|
2
|
|
|
2
|
|
16030
|
use 5.008005; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
87
|
|
3
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
73
|
|
4
|
2
|
|
|
2
|
|
19
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
5
|
2
|
|
|
2
|
|
1664
|
use utf8; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
11
|
|
6
|
2
|
|
|
2
|
|
1828
|
use parent qw/Exporter/; |
|
2
|
|
|
|
|
683
|
|
|
2
|
|
|
|
|
9
|
|
7
|
2
|
|
|
2
|
|
87
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
143
|
|
8
|
2
|
|
|
2
|
|
1143
|
use Encode qw/encode_utf8/; |
|
2
|
|
|
|
|
11986
|
|
|
2
|
|
|
|
|
411
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw/get_genre_name get_genre_id get_parent_genre_name get_parent_genre_id/; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
|
|
1367
|
use constant PARENT_GENRES => [ |
14
|
|
|
|
|
|
|
{genre => 'News', name => 'ニュース/報道'}, # 0x0 |
15
|
|
|
|
|
|
|
{genre => 'Sport', name => 'スポーツ'}, # 0x1 |
16
|
|
|
|
|
|
|
{genre => 'Info', name => '情報/ワイドショー'}, # 0x2 |
17
|
|
|
|
|
|
|
{genre => 'Drama', name => 'ドラマ'}, # 0x3 |
18
|
|
|
|
|
|
|
{genre => 'Music', name => '音楽'}, # 0x4 |
19
|
|
|
|
|
|
|
{genre => 'Variety', name => 'バラエティ'}, # 0x5 |
20
|
|
|
|
|
|
|
{genre => 'Movie', name => '映画'}, # 0x6 |
21
|
|
|
|
|
|
|
{genre => 'Anime', name => 'アニメ/特撮'}, # 0x7 |
22
|
|
|
|
|
|
|
{genre => 'Documentary', name => 'ドキュメンタリー/教養'}, # 0x8 |
23
|
|
|
|
|
|
|
{genre => 'Theater', name => '劇場/公演'}, # 0x9 |
24
|
|
|
|
|
|
|
{genre => 'Hobby', name => '趣味/教育'}, # 0xA |
25
|
|
|
|
|
|
|
{genre => 'Welfare', name => '福祉'}, # 0xB |
26
|
|
|
|
|
|
|
{genre => 'Reserve', name => '予備'}, # 0xC |
27
|
|
|
|
|
|
|
{genre => 'Reserve', name => '予備'}, # 0xD |
28
|
|
|
|
|
|
|
{genre => 'Expansion', name => '拡張'}, # 0xE |
29
|
|
|
|
|
|
|
{genre => 'Other', name => 'その他'}, # 0xF |
30
|
2
|
|
|
2
|
|
18
|
]; |
|
2
|
|
|
|
|
3
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub get_genre_name { |
33
|
19
|
|
|
19
|
1
|
11749
|
my ($parent_genre_id, $child_genre_id) = @_; |
34
|
|
|
|
|
|
|
|
35
|
19
|
100
|
33
|
|
|
90
|
if ((not defined $parent_genre_id) || (not defined $child_genre_id)) { |
36
|
1
|
|
|
|
|
414
|
croak "Parent genre ID and Child genre ID are required"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
18
|
|
|
|
|
42
|
my $parent_genre = _get_parent_genre($parent_genre_id); |
40
|
17
|
|
|
|
|
46
|
my $child_genre_class = __PACKAGE__ . '::ChildGenre::' . $parent_genre->{genre}; |
41
|
17
|
|
|
|
|
1174
|
eval "require $child_genre_class"; ## no critic |
42
|
17
|
|
|
|
|
222
|
return $child_genre_class->new->get_child_genre_name($child_genre_id); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub get_genre_id { |
46
|
15
|
|
|
15
|
1
|
4065
|
my ($name) = @_; |
47
|
15
|
100
|
|
|
|
176
|
croak "Genre name is required" unless $name; |
48
|
|
|
|
|
|
|
|
49
|
14
|
|
|
|
|
19
|
my $child_genre_id; |
50
|
14
|
|
|
|
|
21
|
my $parent_genre_id = 0; |
51
|
14
|
|
|
|
|
23
|
for my $parent_genre (@{+PARENT_GENRES}) { |
|
14
|
|
|
|
|
33
|
|
52
|
109
|
|
|
|
|
246
|
my $child_genre_class = __PACKAGE__ . '::ChildGenre::' . $parent_genre->{genre}; |
53
|
109
|
|
|
|
|
6701
|
eval "require $child_genre_class"; ## no critic |
54
|
109
|
|
|
|
|
284
|
eval { $child_genre_id = $child_genre_class->new->get_child_genre_id($name) }; |
|
109
|
|
|
|
|
454
|
|
55
|
109
|
100
|
|
|
|
18340
|
last if defined $child_genre_id; |
56
|
96
|
|
|
|
|
193
|
$parent_genre_id++; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
14
|
100
|
|
|
|
38
|
if (not defined $child_genre_id) { |
60
|
1
|
|
|
|
|
7
|
croak encode_utf8("No such a genre: $name"); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
13
|
|
|
|
|
89
|
return [$parent_genre_id, $child_genre_id]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get_parent_genre_name { |
67
|
3
|
|
|
3
|
1
|
4500
|
my ($id) = @_; |
68
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
11
|
return encode_utf8(_get_parent_genre($id)->{name}); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub get_parent_genre_id { |
73
|
3
|
|
|
3
|
1
|
3893
|
my ($name) = @_; |
74
|
|
|
|
|
|
|
|
75
|
3
|
100
|
|
|
|
152
|
croak "Parent genre name is required" unless $name; |
76
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
4
|
eval { $name = decode_utf8($name) }; |
|
2
|
|
|
|
|
31
|
|
78
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
5
|
my $id = 0; |
80
|
2
|
|
|
|
|
5
|
for my $genre (@{+PARENT_GENRES}) { |
|
2
|
|
|
|
|
5
|
|
81
|
17
|
100
|
|
|
|
45
|
return $id if $genre->{name} eq $name; |
82
|
16
|
|
|
|
|
21
|
$id++; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
9
|
croak encode_utf8("No such a parent genre $name"); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _get_parent_genre { |
89
|
21
|
|
|
21
|
|
26
|
my ($id) = @_; |
90
|
|
|
|
|
|
|
|
91
|
21
|
100
|
|
|
|
221
|
croak "Parent genre ID is required" if not defined $id; |
92
|
|
|
|
|
|
|
|
93
|
20
|
|
|
|
|
29
|
my $genre = PARENT_GENRES->[$id]; |
94
|
20
|
100
|
66
|
|
|
95
|
if (!$genre || (not defined $genre->{name})) { |
95
|
2
|
|
|
|
|
288
|
croak "No such a parent genre (ID: $id)"; |
96
|
|
|
|
|
|
|
} |
97
|
18
|
|
|
|
|
46
|
return $genre; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
__END__ |