File Coverage

blib/lib/LINE/Bot/API/Event/Base.pm
Criterion Covered Total %
statement 25 37 67.5
branch 2 4 50.0
condition n/a
subroutine 14 26 53.8
pod 0 23 0.0
total 41 90 45.5


line stmt bran cond sub pod time code
1             package LINE::Bot::API::Event::Base;
2 47     47   22306 use strict;
  47         122  
  47         1349  
3 47     47   220 use warnings;
  47         449  
  47         1285  
4              
5 47     47   240 use Carp 'croak';
  47         89  
  47         23308  
6              
7             sub new {
8 17     17 0 45 my($class, %args) = @_;
9 17         62 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 5 sub type { $_[0]->{type} }
14 16     16 0 57307 sub mode { $_[0]->{mode} }
15 2     2 0 10 sub timestamp { $_[0]->{timestamp} }
16              
17             # Unfollow and Leave events don't have this
18 17     17 0 95 sub reply_token { $_[0]->{replyToken} }
19              
20             # type
21 0     0 0 0 sub is_message_event { 0 }
22 0     0 0 0 sub is_follow_event { 0 }
23 0     0 0 0 sub is_unfollow_event { 0 }
24 0     0 0 0 sub is_join_event { 0 }
25 0     0 0 0 sub is_leave_event { 0 }
26 0     0 0 0 sub is_member_join_event { 0 }
27 0     0 0 0 sub is_member_leave_event { 0 }
28 0     0 0 0 sub is_postback_event { 0 }
29 0     0 0 0 sub is_beacon_detection_event { 0 }
30 0     0 0 0 sub is_device_link_event { 0 }
31 0     0 0 0 sub is_device_unlink_event { 0 }
32 0     0 0 0 sub is_account_link_event { 0 }
33              
34             # source field
35 1     1 0 6 sub is_user_event { $_[0]->{source}{type} eq 'user' }
36 4     4 0 17 sub is_group_event { $_[0]->{source}{type} eq 'group' }
37 4     4 0 19 sub is_room_event { $_[0]->{source}{type} eq 'room' }
38              
39 3     3 0 12 sub user_id { $_[0]->{source}{userId} }
40              
41             sub group_id {
42 2     2 0 4 my $self = shift;
43 2 50       5 croak 'This event source is not a group type.' unless $self->is_group_event;
44 2         9 $self->{source}{groupId};
45             }
46              
47             sub room_id {
48 2     2 0 4 my $self = shift;
49 2 50       5 croak 'This event source is not a room type.' unless $self->is_room_event;
50 2         14 $self->{source}{roomId};
51             }
52              
53             1;