File Coverage

blib/lib/AnyEvent/Discord/Payload.pm
Criterion Covered Total %
statement 129 129 100.0
branch 12 24 50.0
condition n/a
subroutine 30 30 100.0
pod n/a
total 171 183 93.4


line stmt bran cond sub pod time code
1 5     5   536 use v5.14;
  10         1438  
2 10     5   1331 use Moops;
  5         53349  
  5         48  
3              
4 5     5   219377 class AnyEvent::Discord::Payload {
  5     4   166  
  5     3   41  
  5     3   10  
  5     3   340  
  5     3   647  
  5     3   2240  
  5     3   47  
  5     3   3314  
  5     3   16  
  5     3   44  
  5     3   718  
  5     3   12  
  5     1   264  
  5     3   32  
  5         8  
  5         500  
  6         5272  
  6         41  
  6         25  
  6         2738  
  6         27601  
  6         446  
  6         443  
  6         3896  
  5         4048  
  5         47  
  5         50147  
  5         21  
  5         59  
  5         1013  
  5         9213  
  5         40  
  5         1775  
  5         3066  
  5         47  
  5         6635  
  5         3253  
  5         35  
  5         165241  
  5         19  
  5         36  
  5         9  
  5         172  
  5         31  
  5         18  
  5         249  
  5         34  
  5         14  
  5         562  
  1         4478  
  2         7  
  3         8053  
5 3     3   2381 use JSON qw(decode_json encode_json);
  3     2   36396  
  3         26  
  2         48097  
  2         29  
  2         416  
6              
7 1         14 our $VERSION = '0.1';
  3         4773  
8 1         5 has version => ( is => 'ro', isa => Str, default => $VERSION );
  3         1284  
9              
10 1         3112 has op => ( is => 'rw', isa => Num );
  3         1216  
11 1         1704 has d => ( is => 'rw' );
  3         1209  
12 1         427 has s => ( is => 'rw' );
13 1         414 has t => ( is => 'rw' );
14              
15 3 50   3   71693 method from_json($class: Str $json) {
  3 50   3   7  
  3 50   2   590  
  3 50   2   24  
  3 50       7  
  3         345  
  1         417  
  2         8  
  2         4  
  2         11  
  2         4  
  2         4  
  2         55  
  5         3632  
  5         20  
  2         20  
  2         5  
  2         289  
  2         4645  
  2         18  
  2         460  
16 5         15 $class->new(decode_json($json));
17             }
18              
19 3 50   3   6994 method from_hashref($class: HashRef $ref) {
  3 50   3   10  
  3 50   5   662  
  3 50   2   25  
  3 50       7  
  3         326  
  2         5954  
  5         14  
  5         8  
  5         16  
  5         19  
  5         9  
  5         102  
  1         72  
  1         4  
  2         16  
  2         15  
  2         239  
  2         2299  
  2         6  
  2         356  
20 1         1 $class->new($ref);
21             }
22              
23 3 50   3   3351 method as_json() {
  3 50   1   7  
  3     2   447  
  2         14  
  1         20  
  2         1596  
  2         25534  
  3         13544  
  3         40  
  3         16  
24 2         14 return encode_json({
25             op => $self->op,
26             d => $self->d,
27             });
28             }
29             }
30              
31             1;
32              
33             =pod
34              
35             =head1 NAME
36              
37             AnyEvent::Discord::Payload - Represents a Discord payload
38              
39             =head1 DESCRIPTION
40              
41             https://discord.com/developers/docs/topics/gateway
42              
43             =head1 ACCESSORS
44              
45             =over 4
46              
47             =item op (Number)
48              
49             Opcode
50              
51             =item d (HashRef)
52              
53             Data structure for message
54              
55             =item t (String)
56              
57             Event name
58              
59             =back
60              
61             =head1 CAVEATS
62              
63             This is incredibly unfinished.
64              
65             =head1 AUTHOR
66              
67             Nick Melnick <nmelnick@cpan.org>
68              
69             =head1 COPYRIGHT AND LICENSE
70              
71             This software is copyright (c) 2021, Nick Melnick.
72              
73             This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
74              
75             =cut