File Coverage

blib/lib/LINE/Bot/API/Builder/SendMessage.pm
Criterion Covered Total %
statement 36 36 100.0
branch 14 14 100.0
condition n/a
subroutine 13 13 100.0
pod 0 11 0.0
total 63 74 85.1


line stmt bran cond sub pod time code
1             package LINE::Bot::API::Builder::SendMessage;
2 46     46   313 use strict;
  46         91  
  46         1355  
3 46     46   274 use warnings;
  46         97  
  46         24137  
4              
5             sub new {
6 28     28 0 62954 my($class, ) = @_;
7 28         113 bless [], $class;
8             }
9              
10             sub build {
11 39     39 0 16787 my($self, ) = @_;
12 39         230 +[ @$self ];
13             }
14              
15             sub add {
16 37     37 0 91 my($self, $message) = @_;
17 37         83 push @{ $self }, $message;
  37         127  
18 37         101 $self;
19             }
20              
21             sub add_text {
22 16     16 0 90 my($self, %args) = @_;
23             $self->add(+{
24             type => 'text',
25             text => $args{text},
26             $args{sender} ? (
27             sender => $args{sender},
28             ) : (),
29             $args{emojis} ? (
30             emojis => $args{emojis},
31 16 100       120 ):(),
    100          
32             });
33              
34 16         54 $self;
35             }
36              
37             sub add_image {
38 3     3 0 24 my($self, %args) = @_;
39             $self->add(+{
40             $args{sender} ? (
41             sender => $args{sender},
42             ) : (),
43             type => 'image',
44             originalContentUrl => $args{image_url},
45             previewImageUrl => $args{preview_url},
46 3 100       28 });
47              
48 3         9 $self;
49             }
50              
51             sub add_video {
52 3     3 0 26 my($self, %args) = @_;
53             $self->add(+{
54             $args{sender} ? (
55             sender => $args{sender},
56             ) : (),
57             type => 'video',
58             originalContentUrl => $args{video_url},
59             previewImageUrl => $args{preview_url},
60 3 100       29 });
61              
62 3         7 $self;
63             }
64              
65             sub add_audio {
66 3     3 0 26 my($self, %args) = @_;
67             $self->add(+{
68             $args{sender} ? (
69             sender => $args{sender},
70             ) : (),
71             type => 'audio',
72             originalContentUrl => $args{audio_url},
73             duration => $args{duration},
74 3 100       28 });
75              
76 3         9 $self;
77             }
78              
79             sub add_location {
80 3     3 0 33 my($self, %args) = @_;
81             $self->add(+{
82             $args{sender} ? (
83             sender => $args{sender},
84             ) : (),
85             type => 'location',
86             title => $args{title},
87             address => $args{address},
88             latitude => $args{latitude},
89             longitude => $args{longitude},
90 3 100       28 });
91              
92 3         10 $self;
93             }
94              
95             sub add_sticker {
96 3     3 0 31 my($self, %args) = @_;
97             $self->add(+{
98             $args{sender} ? (
99             sender => $args{sender},
100             ) : (),
101             type => 'sticker',
102             packageId => $args{package_id},
103             stickerId => $args{sticker_id},
104 3 100       28 });
105              
106 3         9 $self;
107             }
108              
109             # If you want this method to use, I recommend using LINE::Bot::API::Builder::ImagemapMessage class for you.
110             sub add_imagemap {
111 2     2 0 6 my($self, $imagemap) = @_;
112 2         6 $self->add($imagemap);
113             }
114              
115             # If you want this method to use, I recommend using LINE::Bot::API::Builder::TemplateMessage class for you.
116             sub add_template {
117 4     4 0 10 my($self, $template) = @_;
118 4         12 $self->add($template);
119             }
120              
121             1;