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   569 use v5.14;
  10         1590  
2 10     5   1330 use Moops;
  5         51318  
  5         83  
3              
4 5     5   219609 class AnyEvent::Discord::Payload {
  5     4   510  
  5     3   43  
  5     3   11  
  5     3   350  
  5     3   572  
  5     3   2257  
  5     3   49  
  5     3   3248  
  5     3   10  
  5     3   39  
  5     3   759  
  5     3   11  
  5     1   277  
  5     3   33  
  5         8  
  5         464  
  6         4649  
  6         43  
  6         19  
  6         2693  
  6         27173  
  6         463  
  6         440  
  6         3608  
  5         3853  
  5         39  
  5         50173  
  5         10  
  5         55  
  5         1039  
  5         9270  
  5         45  
  5         1688  
  5         3149  
  5         77  
  5         6553  
  5         3202  
  5         49  
  5         166639  
  5         19  
  5         29  
  5         11  
  5         179  
  5         38  
  5         19  
  5         287  
  5         31  
  5         18  
  5         574  
  1         4433  
  2         8  
  3         8216  
5 3     3   2342 use JSON qw(decode_json encode_json);
  3     2   36388  
  3         21  
  2         46900  
  2         7  
  2         374  
6              
7 1         13 our $VERSION = '0.1';
  3         4787  
8 1         6 has version => ( is => 'ro', isa => Str, default => $VERSION );
  3         1338  
9              
10 1         2855 has op => ( is => 'rw', isa => Num );
  3         1210  
11 1         1612 has d => ( is => 'rw' );
  3         1266  
12 1         429 has s => ( is => 'rw' );
13 1         411 has t => ( is => 'rw' );
14              
15 3 50   3   70587 method from_json($class: Str $json) {
  3 50   3   8  
  3 50   2   537  
  3 50   2   24  
  3 50       7  
  3         340  
  1         444  
  2         7  
  2         5  
  2         9  
  2         5  
  2         4  
  2         60  
  5         3615  
  5         30  
  2         17  
  2         4  
  2         247  
  2         4768  
  2         5  
  2         408  
16 5         19 $class->new(decode_json($json));
17             }
18              
19 3 50   3   7159 method from_hashref($class: HashRef $ref) {
  3 50   3   7  
  3 50   5   607  
  3 50   2   24  
  3 50       6  
  3         356  
  2         5772  
  5         17  
  5         7  
  5         15  
  5         9  
  5         10  
  5         104  
  1         74  
  1         4  
  2         16  
  2         4  
  2         241  
  2         2206  
  2         5  
  2         286  
20 1         2 $class->new($ref);
21             }
22              
23 3 50   3   3334 method as_json() {
  3 50   1   8  
  3     2   422  
  2         12  
  1         21  
  2         1506  
  2         24133  
  3         13327  
  3         42  
  3         16  
24 2         12 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