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 51     51   25612 use strict;
  51         113  
  51         1510  
3 51     51   249 use warnings;
  51         581  
  51         1408  
4              
5 51     51   273 use Carp 'croak';
  51         95  
  51         26939  
6              
7             sub new {
8 17     17 0 54 my($class, %args) = @_;
9 17         79 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 16     16 0 78257 sub mode { $_[0]->{mode} }
15 2     2 0 331 sub timestamp { $_[0]->{timestamp} }
16              
17             # Unfollow and Leave events don't have this
18 17     17 0 140 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 8 sub is_user_event { $_[0]->{source}{type} eq 'user' }
36 4     4 0 28 sub is_group_event { $_[0]->{source}{type} eq 'group' }
37 4     4 0 29 sub is_room_event { $_[0]->{source}{type} eq 'room' }
38              
39 3     3 0 18 sub user_id { $_[0]->{source}{userId} }
40              
41             sub group_id {
42 2     2 0 6 my $self = shift;
43 2 50       7 croak 'This event source is not a group type.' unless $self->is_group_event;
44 2         14 $self->{source}{groupId};
45             }
46              
47             sub room_id {
48 2     2 0 6 my $self = shift;
49 2 50       8 croak 'This event source is not a room type.' unless $self->is_room_event;
50 2         19 $self->{source}{roomId};
51             }
52              
53             1;