Mattermost/V4/API/Object.pm

filter: Statementstmt 88.8% 24 / 27 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 86.1% 31 / 36 CC 2 SCAR 3.2
CC
2
Cov
86%
_from_epoch
2.0
_related_args
2.0
BEGIN
1.0
CRAP 1.4
« Mattermost/V4/API/Object/Role/BelongingToPost.pm ↑ Summary Mattermost/V4/API/Object/Emoji.pm »
1 package WebService::Mattermost::V4::API::Object;
2  
3 # ABSTRACT: Base class for results returned from the API.
4  
5 12 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Types::Standard qw(HashRef InstanceOf Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 ▶use WebService::Mattermost::V4::API;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 12 with qw(
12 WebService::Mattermost::Role::Returns
13 WebService::Mattermost::V4::API::Role::NewRelatedResource
14 );
15  
16 ################################################################################
17  
18 12 has [ qw(auth_token base_url) ] => (is => 'ro', isa => Str, required => 1);
19 12 has raw_data => (is => 'ro', isa => HashRef, required => 1);
20  
21 12 has api => (is => 'ro', isa => InstanceOf['WebService::Mattermost::V4::API'], lazy => 1, builder => 1);
22  
23 ################################################################################
24  
25 sub _from_epoch {
26 3 ▶ my $self = shift;
Subroutine _from_epoch: called CC=2 SCAR=7.0
27 3 my $unix_timestamp = shift;
28  
29 3 ▶ return undef unless $unix_timestamp;
Branch: 1 branch
BranchTrueFalseTotal
unless $unix_timestamp 0 3 3
30  
31 # The timestamp is too precise - trim away the end
32 3 $unix_timestamp =~ s/...$//s;
33  
34 3 return DateTime->from_epoch(epoch => $unix_timestamp);
35 }
36  
37 sub _related_args {
38 0 ▶ my $self = shift;
Subroutine _related_args: not called CC=1 SCAR=6.9
39 0 my $args = shift;
40  
41 return {
42 0 auth_token => $self->auth_token,
43 base_url => $self->base_url,
44 raw_data => $args,
45 };
46 }
47  
48 ################################################################################
49  
50 sub _build_api {
51 2 ▶ my $self = shift;
Subroutine _build_api: called CC=1 SCAR=0.0
52  
53 2 return WebService::Mattermost::V4::API->new({
54 auth_token => $self->auth_token,
55 base_url => $self->base_url,
56 });
57 }
58  
59 ################################################################################
60  
61 12 1;
62  
63 __END__
64  
65 =pod
66  
67 =encoding UTF-8
68  
69 =head1 NAME
70  
71 WebService::Mattermost::V4::API::Object - Base class for results returned from the API.
72  
73 =head1 VERSION
74  
75 version 0.28
76  
77 =head1 DESCRIPTION
78  
79 Base class for wrappers for individual results returned from the Mattermost API.
80  
81 =head2 METHODS
82  
83 =over 4
84  
85 =item C<_from_epoch()>
86  
87 Converts a UNIX timestamp from Mattermost to a DateTime object. The last three
88 characters of the timestamp are trimmed to make it the expected length.
89  
90 =back
91  
92 =head2 ATTRIBUTES
93  
94 =over 4
95  
96 =item C<raw_data>
97  
98 The raw response from Mattermost.
99  
100 =item C<auth_token>
101  
102 The current session's auth token, for rebuilding the API.
103  
104 =item C<base_url>
105  
106 The server's base URL.
107  
108 =item C<api>
109  
110 API access for the Object classes.
111  
112 =back
113  
114 =head1 AUTHOR
115  
116 Mike Jones <mike@netsplit.org.uk>
117  
118 =head1 COPYRIGHT AND LICENSE
119  
120 This software is Copyright (c) 2020 by Mike Jones.
121  
122 This is free software, licensed under:
123  
124 The MIT (X11) License
125  
126 =cut
« Mattermost/V4/API/Object/Role/BelongingToPost.pm ↑ Summary Mattermost/V4/API/Object/Emoji.pm »