File Coverage

blib/lib/LINE/Bot/API/Event/Base.pm
Criterion Covered Total %
statement 27 42 64.2
branch 2 4 50.0
condition n/a
subroutine 16 31 51.6
pod 0 28 0.0
total 45 105 42.8


line stmt bran cond sub pod time code
1             package LINE::Bot::API::Event::Base;
2 53     53   28222 use strict;
  53         113  
  53         2208  
3 53     53   403 use warnings;
  53         135  
  53         2990  
4              
5 53     53   301 use Carp 'croak';
  53         113  
  53         36351  
6              
7             sub new {
8 20     20 0 70 my($class, %args) = @_;
9 20         136 bless { %args }, $class;
10             }
11              
12             # Accessors for Event-level properties. https://developers.line.biz/en/reference/messaging-api/#common-properties
13 1     1 0 6 sub type { $_[0]->{type} }
14 19     19 0 114906 sub mode { $_[0]->{mode} }
15 2     2 0 13 sub timestamp { $_[0]->{timestamp} }
16 20     20 0 148 sub webhook_event_id { $_[0]->{webhookEventId} }
17              
18             # Whether the webhook event is a redelivered one or not.
19             # https://developers.line.biz/en/docs/messaging-api/receiving-messages/#redelivered-webhooks
20 20     20 0 211 sub is_redelivery { $_[0]->{deliveryContext}{isRedelivery} }
21              
22             # Unfollow and Leave events don't have this
23 18     18 0 6750 sub reply_token { $_[0]->{replyToken} }
24              
25             # type
26 0     0 0 0 sub is_message_event { 0 }
27 0     0 0 0 sub is_follow_event { 0 }
28 0     0 0 0 sub is_unfollow_event { 0 }
29 0     0 0 0 sub is_join_event { 0 }
30 0     0 0 0 sub is_leave_event { 0 }
31 0     0 0 0 sub is_member_join_event { 0 }
32 0     0 0 0 sub is_member_leave_event { 0 }
33 0     0 0 0 sub is_postback_event { 0 }
34 0     0 0 0 sub is_beacon_detection_event { 0 }
35 0     0 0 0 sub is_device_link_event { 0 }
36 0     0 0 0 sub is_device_unlink_event { 0 }
37 0     0 0 0 sub is_account_link_event { 0 }
38 0     0 0 0 sub is_unsend_event { 0 }
39 0     0 0 0 sub is_video_viewing_complete_event { 0 }
40 0     0 0 0 sub is_unknown_event { 0 }
41              
42             # source field
43 1     1 0 56 sub is_user_event { $_[0]->{source}{type} eq 'user' }
44 4     4 0 28 sub is_group_event { $_[0]->{source}{type} eq 'group' }
45 4     4 0 29 sub is_room_event { $_[0]->{source}{type} eq 'room' }
46              
47 3     3 0 603 sub user_id { $_[0]->{source}{userId} }
48              
49             sub group_id {
50 2     2 0 1187 my $self = shift;
51 2 50       7 croak 'This event source is not a group type.' unless $self->is_group_event;
52 2         12 $self->{source}{groupId};
53             }
54              
55             sub room_id {
56 2     2 0 1168 my $self = shift;
57 2 50       7 croak 'This event source is not a room type.' unless $self->is_room_event;
58 2         12 $self->{source}{roomId};
59             }
60              
61             1;