SFDC/Role/Session.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 47 CC 3 SCAR 15.5
CC
3
Cov
0%
_call
12.0
_buildURL
2.0
_sleep
2.0
CRAP 4.7
1 package WWW::SFDC::Role::Session;
2 # ABSTRACT: Provides a transparent interface to WWW::SFDC::SessionManager
3  
4 use 5.12.0;
5 use strict;
6 use warnings;
7  
8 use Moo::Role;
9 use Module::Loaded;
10  
11 use WWW::SFDC::SessionManager;
12  
13  
14 requires qw'_extractURL';
15  
16 has 'creds',
17 is => 'ro',
18 trigger => sub {WWW::SFDC::SessionManager->instance(shift->creds())};
19  
20 has 'url',
21 is => 'ro',
22 lazy => 1,
23 builder => '_buildURL';
24  
25 has 'pollInterval',
26 is => 'rw',
27 default => 15;
28  
29 sub _buildURL {
30 my $self = shift;
31 return $self->_extractURL(WWW::SFDC::SessionManager->instance()->loginResult());
32 }
33  
34 sub _call {
35 my $self = shift;
36 my $req = WWW::SFDC::SessionManager->instance()->call($self->url(), $self->uri(), @_);
37  
38 return $req->result(),
39 (defined $req->paramsout() ? $req->paramsout() : ()),
40 (defined $req->headers() ? $req->headers() : ());
41 }
42  
43 sub _sleep {
44 my $self = shift;
45 sleep $self->pollInterval;
46 }
47  
48 1;
49  
50 __END__
51  
52 =pod
53  
54 =head1 NAME
55  
56 WWW::SFDC::Role::Session - Provides a transparent interface to WWW::SFDC::SessionManager
57  
58 =head1 VERSION
59  
60 version 0.22
61  
62 =head1 SYNOPSIS
63  
64 package Example;
65 use Moo;
66 with "WWW::SFDC::Role::Session";
67  
68 sub _extractURL {
69 # this is a required method. $_[0] is self, as normal.
70 # $_[1] is the loginResult hash, which has a serverUrl as
71 # well as a metadataServerUrl defined.
72 return $_[1]->{serverUrl};
73 }
74  
75 # uri is a required property, containing the default namespace
76 # for the SOAP request.
77 has 'uri', is => 'ro', default => 'urn:partner.soap.salesforce.com';
78  
79 sub doSomething {
80 my $self = shift;
81 # this uses the above-defined uri and url, and generates
82 # a new sessionId upon an INVALID_SESSION_ID error:
83 return $self->_call('method', @_);
84 }
85  
86 1;
87  
88 =head1 BUGS
89  
90 Please report any bugs or feature requests at L<https://github.com/alexander-brett/WWW-SFDC/issues>.
91  
92 =head1 SUPPORT
93  
94 You can find documentation for this module with the perldoc command.
95  
96 perldoc WWW::SFDC::Role::Session
97  
98 You can also look for information at L<https://github.com/alexander-brett/WWW-SFDC>
99  
100 =head1 AUTHOR
101  
102 Alexander Brett <alexander.brett@sophos.com>
103  
104 =head1 COPYRIGHT AND LICENSE
105  
106 This software is Copyright (c) 2015 by Sophos Limited.
107  
108 This is free software, licensed under:
109  
110 The MIT (X11) License
111  
112 The full text of the license can be found in the
113 F<LICENSE> file included with this distribution.
114  
115 =cut