File Coverage

blib/lib/LINE/Bot/API/Builder/ImagemapMessage.pm
Criterion Covered Total %
statement 27 29 93.1
branch 3 4 75.0
condition 1 2 50.0
subroutine 7 7 100.0
pod 0 5 0.0
total 38 47 80.8


line stmt bran cond sub pod time code
1             package LINE::Bot::API::Builder::ImagemapMessage;
2 1     1   447 use strict;
  1         2  
  1         23  
3 1     1   5 use warnings;
  1         1  
  1         317  
4              
5             sub new {
6 2     2 0 608 my($class, %args) = @_;
7             my %o = (
8             type => 'imagemap',
9             baseUrl => $args{base_url},
10             altText => $args{alt_text},
11             baseSize => +{
12             width => $args{base_width},
13             height => $args{base_height},
14             },
15 2   50     17 actions => $args{actions} // [],
16             );
17              
18 2 100       5 if ($args{video}) {
19 1         3 $o{video} = {};
20 1         3 for my $attr (qw(originalContentUrl previewImageUrl)) {
21 2         5 $o{video}{$attr} = $args{video}{$attr};
22             }
23 1         4 for my $attr (qw(x y width height)) {
24 4         8 $o{video}{area}{$attr} = $args{video}{area}{$attr};
25             }
26              
27 1 50       3 if ($args{video}{externalLink}) {
28 0         0 for my $attr (qw(label linkUri)) {
29 0         0 $o{video}{externalLink}{$attr} = $args{video}{externalLink}{$attr};
30             }
31             }
32             }
33              
34 2         8 return bless \%o, $class;
35             }
36              
37             sub build {
38 2     2 0 22 my($self, ) = @_;
39 2         3 +{ %{ $self } };
  2         14  
40             }
41              
42             sub add_action {
43 2     2 0 6 my($self, $action) = @_;
44 2         3 push @{ $self->{actions} }, $action;
  2         6  
45 2         8 $self;
46             }
47              
48             sub add_uri_action {
49 1     1 0 5 my($self, %args) = @_;
50             $self->add_action(+{
51             type => 'uri',
52             linkUri => $args{uri},
53             area => +{
54             x => $args{area_x},
55             y => $args{area_y},
56             width => $args{area_width},
57             height => $args{area_height},
58             },
59 1         7 });
60             }
61              
62             sub add_message_action {
63 1     1 0 3 my($self, %args) = @_;
64             $self->add_action(+{
65             type => 'message',
66             text => $args{text},
67             area => +{
68             x => $args{area_x},
69             y => $args{area_y},
70             width => $args{area_width},
71             height => $args{area_height},
72             },
73 1         17 });
74             }
75              
76             1;