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   643 use v5.14;
  10         1462  
2 10     5   1387 use Moops;
  5         56896  
  5         47  
3              
4 5     5   237080 class AnyEvent::Discord::Payload {
  5     4   166  
  5     3   37  
  5     3   14  
  5     3   342  
  5     3   622  
  5     3   2396  
  5     3   51  
  5     3   3217  
  5     3   12  
  5     3   42  
  5     3   709  
  5     3   13  
  5     1   302  
  5     3   30  
  5         10  
  5         454  
  6         4885  
  6         47  
  6         14  
  6         3135  
  6         27608  
  6         549  
  6         447  
  6         4039  
  5         4180  
  5         40  
  5         54166  
  5         11  
  5         50  
  5         1204  
  5         9880  
  5         48  
  5         2127  
  5         3388  
  5         49  
  5         6714  
  5         3501  
  5         42  
  5         182744  
  5         19  
  5         33  
  5         34  
  5         140  
  5         37  
  5         32  
  5         311  
  5         34  
  5         10  
  5         578  
  1         4466  
  2         10  
  3         7625  
5 3     3   2933 use JSON qw(decode_json encode_json);
  3     2   44791  
  3         18  
  2         49668  
  2         6  
  2         427  
6              
7 1         12 our $VERSION = '0.1';
  3         4666  
8 1         5 has version => ( is => 'ro', isa => Str, default => $VERSION );
  3         1337  
9              
10 1         3116 has op => ( is => 'rw', isa => Num );
  3         1247  
11 1         1672 has d => ( is => 'rw' );
  3         1231  
12 1         431 has s => ( is => 'rw' );
13 1         403 has t => ( is => 'rw' );
14              
15 3 50   3   70823 method from_json($class: Str $json) {
  3 50   3   8  
  3 50   2   552  
  3 50   2   26  
  3 50       7  
  3         350  
  1         398  
  2         10  
  2         5  
  2         15  
  2         5  
  2         4  
  2         77  
  5         3727  
  5         19  
  2         17  
  2         5  
  2         259  
  2         5759  
  2         5  
  2         447  
16 5         15 $class->new(decode_json($json));
17             }
18              
19 3 50   3   7208 method from_hashref($class: HashRef $ref) {
  3 50   3   8  
  3 50   5   607  
  3 50   2   25  
  3 50       7  
  3         318  
  2         6353  
  5         16  
  5         11  
  5         16  
  5         9  
  5         10  
  5         107  
  1         91  
  1         5  
  2         16  
  2         9  
  2         237  
  2         2386  
  2         6  
  2         311  
20 1         3 $class->new($ref);
21             }
22              
23 3 50   3   3325 method as_json() {
  3 50   1   8  
  3     2   435  
  2         15  
  1         22  
  2         1585  
  2         25632  
  3         13182  
  3         39  
  3         13  
24 2         17 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