File Coverage

blib/lib/WebService/Mattermost/Role/UserAgent.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 28 28 100.0


line stmt bran cond sub pod time code
1             package WebService::Mattermost::Role::UserAgent;
2:

3: # ABSTRACT: Internal user agent role. 4:
5: use Moo::Role;
6: use Types::Standard 'InstanceOf';
7:
8: use WebService::Mattermost::Util::UserAgent;
9: use WebService::Mattermost::Helper::Alias 'util';
10:
11: ################################################################################
12:
13: has ua => (is => 'ro', isa => InstanceOf['Mojo::UserAgent'], lazy => 1, builder => 1);
14:
15: ################################################################################
16:
17: sub mmauthtoken {
18: my $self = shift;
19: my $token = shift;
20:
21: return sprintf 'MMAUTHTOKEN=%s', $token;
22: }
23:
24: sub bearer {
25: my $self = shift;
26: my $token = shift;
27:
28: return sprintf 'Bearer %s', $token;
29: }
30:
31: ################################################################################
32:
33: sub _build_ua {
34: return util('UserAgent')->new->ua;
35: }
36:
37: ################################################################################
38:
39: 1;
40:
41: __END__
42:
43: =pod
44:
45: =encoding UTF-8
46:
47: =head1 NAME
48:
49: WebService::Mattermost::Role::UserAgent - Internal user agent role.
50:
51: =head1 VERSION
52:
53: version 0.28
54:
55: =head1 DESCRIPTION
56:
57: Bundles C<Mojo::UserAgent> and required parameters for HTTP headers.
58:
59: =head2 USAGE
60:
61: use Moo;
62:
63: with 'WebService::Mattermost::Role::UserAgent';
64:
65: sub something {
66: my $self = shift;
67:
68: my $bearer_header = $self->bearer;
69: my $mmauthtoken = $self->mmauthtoken;
70:
71: # Methods from Mojo::UserAgent
72: $self->ua->post(
73: # ...
74: );
75: }
76:
77: =head2 ATTRIBUTES
78:
79: =over 4
80:
81: =item C<ua>
82:
83: A C<Mojo::UserAgent> object.
84:
85: =back
86:
87: =head2 METHODS
88:
89: =over 4
90:
91: =item C<mmauthtoken()>
92:
93: Formats the C<MMAUTHTOKEN> header.
94:
95: =item C<bearer>
96:
97: Formats the C<Bearer> header.
98:
99: =back
100:
101: =head1 AUTHOR
102:
103: Mike Jones <mike@netsplit.org.uk>
104:
105: =head1 COPYRIGHT AND LICENSE
106:
107: This software is Copyright (c) 2020 by Mike Jones.
108:
109: This is free software, licensed under:
110:
111: The MIT (X11) License
112:
113: =cut
114: