File Coverage

blib/lib/LINE/Bot/API/Builder/TemplateMessage.pm
Criterion Covered Total %
statement 79 80 98.7
branch n/a
condition 5 10 50.0
subroutine 31 32 96.8
pod 0 4 0.0
total 115 126 91.2


line stmt bran cond sub pod time code
1             package LINE::Bot::API::Builder::TemplateMessage;
2 1     1   500 use strict;
  1         3  
  1         30  
3 1     1   6 use warnings;
  1         2  
  1         411  
4              
5             sub new_buttons {
6 1     1 0 14 my($class, %args) = @_;
7 1         8 LINE::Bot::API::Builder::TemplateMessage::Buttons->new(%args);
8             }
9              
10             sub new_confirm {
11 1     1 0 8 my($class, %args) = @_;
12 1         7 LINE::Bot::API::Builder::TemplateMessage::Confirm->new(%args);
13             }
14              
15             sub new_carousel {
16 1     1 0 8 my($class, %args) = @_;
17 1         7 LINE::Bot::API::Builder::TemplateMessage::Carousel->new(%args);
18             }
19              
20             sub new_image_carousel {
21 1     1 0 8 my($class, %args) = @_;
22 1         7 LINE::Bot::API::Builder::TemplateMessage::ImageCarousel->new(%args);
23             }
24              
25              
26             package LINE::Bot::API::Builder::TemplateMessage::ActionBase {
27              
28             sub add_action {
29 6     6   13 my($self, $action) = @_;
30 6         8 push @{ $self->_actions }, $action;
  6         13  
31 6         46 $self;
32             }
33              
34             sub add_postback_action {
35 3     3   14 my($self, %args) = @_;
36             $self->add_action(+{
37             type => 'postback',
38             label => $args{label},
39             data => $args{data},
40             text => $args{text},
41 3         26 });
42             }
43              
44             sub add_message_action {
45 3     3   11 my($self, %args) = @_;
46             $self->add_action(+{
47             type => 'message',
48             label => $args{label},
49             text => $args{text},
50 3         22 });
51             }
52              
53             sub add_uri_action {
54 3     3   12 my($self, %args) = @_;
55             $self->add_action(+{
56             type => 'uri',
57             label => $args{label},
58             uri => $args{uri},
59 3         10 });
60             }
61             }
62              
63             package LINE::Bot::API::Builder::TemplateMessage::Buttons {
64 1     1   8 use parent -norequire, 'LINE::Bot::API::Builder::TemplateMessage::ActionBase';
  1         2  
  1         6  
65              
66             sub new {
67 1     1   5 my($class, %args) = @_;
68             bless {
69             type => 'template',
70             altText => $args{alt_text},
71             template => +{
72             type => 'buttons',
73             thumbnailImageUrl => $args{image_url},
74             title => $args{title},
75             text => $args{text},
76 1   50     19 actions => $args{actions} // +[],
77             },
78             }, $class;
79             }
80              
81             sub build {
82 1     1   7 my($self, ) = @_;
83 1         2 +{ %{ $self } };
  1         8  
84             }
85              
86 3     3   10 sub _actions { $_[0]{template}{actions} }
87             }
88              
89             package LINE::Bot::API::Builder::TemplateMessage::Confirm {
90 1     1   212 use parent -norequire, 'LINE::Bot::API::Builder::TemplateMessage::ActionBase';
  1         2  
  1         5  
91              
92             sub new {
93 1     1   3 my($class, %args) = @_;
94             bless {
95             type => 'template',
96             altText => $args{alt_text},
97             template => +{
98             type => 'confirm',
99             text => $args{text},
100 1   50     14 actions => $args{actions} // +[],
101             },
102             }, $class;
103             }
104              
105             sub build {
106 1     1   6 my($self, ) = @_;
107 1         2 +{ %{ $self } };
  1         8  
108             }
109              
110 0     0   0 sub _actions { $_[0]{template}{actions} }
111             }
112              
113             package LINE::Bot::API::Builder::TemplateMessage::Carousel {
114              
115             sub new {
116 1     1   4 my($class, %args) = @_;
117             bless {
118             type => 'template',
119             altText => $args{alt_text},
120             template => +{
121             type => 'carousel',
122 1   50     9 columns => $args{columns} // +[],
123             },
124             }, $class;
125             }
126              
127             sub build {
128 1     1   2 my($self, ) = @_;
129 1         3 +{ %{ $self } };
  1         5  
130             }
131              
132             sub add_column {
133 1     1   3 my($self, $column) = @_;
134 1         2 push @{ $self->{template}{columns} }, $column;
  1         7  
135 1         3 $self;
136             }
137             }
138              
139             package LINE::Bot::API::Builder::TemplateMessage::ImageCarousel {
140              
141             sub new {
142 1     1   3 my($class, %args) = @_;
143             bless {
144             type => 'template',
145             altText => $args{alt_text},
146             template => +{
147             type => 'image_carousel',
148 1   50     11 columns => $args{columns} // +[],
149             },
150             }, $class;
151             }
152              
153             sub build {
154 1     1   6 my($self, ) = @_;
155 1         3 +{ %{ $self } };
  1         5  
156             }
157              
158             sub add_column {
159 3     3   8 my($self, $column) = @_;
160 3         3 push @{ $self->{template}{columns} }, $column;
  3         10  
161 3         10 $self;
162             }
163             }
164              
165             package LINE::Bot::API::Builder::TemplateMessage::Column {
166 1     1   439 use parent -norequire, 'LINE::Bot::API::Builder::TemplateMessage::ActionBase';
  1         2  
  1         6  
167              
168             sub new {
169 1     1   10 my($class, %args) = @_;
170             bless {
171             thumbnailImageUrl => $args{image_url},
172             title => $args{title},
173             text => $args{text},
174 1   50     11 actions => $args{actions} // +[],
175             }, $class;
176             }
177              
178             sub build {
179 1     1   12 my($self, ) = @_;
180 1         4 +{ %{ $self } };
  1         8  
181             }
182              
183 3     3   9 sub _actions { $_[0]{actions} }
184             }
185              
186             package LINE::Bot::API::Builder::TemplateMessage::ImageColumn {
187 1     1   188 use parent -norequire, 'LINE::Bot::API::Builder::TemplateMessage::ActionBase';
  1         3  
  1         4  
188              
189             sub new {
190 3     3   24 my($class, %args) = @_;
191             bless {
192             imageUrl => $args{image_url},
193 3         31 action => undef,
194             }, $class;
195             }
196              
197             sub build {
198 3     3   15 my($self, ) = @_;
199 3         4 +{ %{ $self } };
  3         15  
200             }
201              
202             sub add_action {
203 3     3   14 my($self, $action) = @_;
204 3         7 $self->{action} = $action;
205 3         9 $self;
206             }
207             }
208              
209             1;