File Coverage

blib/lib/Business/cXML/Credential.pm
Criterion Covered Total %
statement 37 37 100.0
branch 6 6 100.0
condition n/a
subroutine 11 11 100.0
pod 2 2 100.0
total 56 56 100.0


line stmt bran cond sub pod time code
1             =encoding utf-8
2              
3             =head1 NAME
4              
5             Business::cXML::Credential - cXML credential
6              
7             =head1 SYNOPSIS
8              
9             use Business::cXML::Transmission;
10             $msg = new Business::cXML::Transmission $incoming_cxml_string;
11             print $msg->to->id; # Fetches Identity string from the To credential
12              
13             =head1 DESCRIPTION
14              
15             Object representation of cXML C<To>, C<From> and C<Sender> (default).
16              
17             =head1 METHODS
18              
19             See L<Business::cXML::Object/COMMON METHODS>.
20              
21             =head1 PROPERTY METHODS
22              
23             See L<Business::cXML::Object/PROPERTY METHODS> for how the following operate.
24              
25             =over
26              
27             =cut
28              
29 7     7   101 use 5.014;
  7         19  
30 7     7   31 use strict;
  7         11  
  7         237  
31              
32             use base qw(Business::cXML::Object);
33 7     7   33  
  7         17  
  7         2706  
34             use constant NODENAME => 'Sender';
35 7     7   41 use constant PROPERTIES => (
  7         13  
  7         403  
36 7         360 _note => undef,
37             domain => 'NetworkId',
38             id => ' ',
39             secret => undef,
40             useragent => undef,
41             type => undef,
42             lang => undef,
43             contact => undef,
44             );
45 7     7   35 use constant OBJ_PROPERTIES => (
  7         11  
46 7         301 contact => 'Business::cXML::Contact',
47             );
48 7     7   35  
  7         24  
49             use Business::cXML;
50 7     7   447 use Business::cXML::Contact;
  7         11  
  7         333  
51 7     7   2754 use XML::LibXML::Ferry;
  7         21  
  7         213  
52 7     7   37  
  7         14  
  7         1433  
53             my ($self, $el) = @_;
54              
55 73     73 1 164 $el->ferry($self, {
56             # domain attribute is implicit
57 73         619 # type attribute is implicit
58             Credential => {
59             # We will only consider the last Credential if there are multiples
60             Identity => 'id',
61             SharedSecret => 'secret',
62             DigitalSignature => '__OBSOLETE',
63             CredentialMac => '__UNIMPLEMENTED',
64             },
65             Correspondent => {
66             preferredLanguage => 'lang',
67             # We will implicitly keep only the last Contact if there are multiples
68             Contact => [ 'contact', 'Business::cXML::Contact' ],
69             },
70             });
71             }
72              
73             my ($self, $doc) = @_;
74             my $node = $doc->create($self->{_nodeName});
75             my $cred = $node->add('Credential', undef, domain => $self->{domain}, type => $self->{type});
76 67     67 1 304 $cred->add('Identity', $self->{id});
77 67         150 $cred->add('SharedSecret', $self->{secret}) if $self->{secret};
78 67         823 # UNIMPLEMENTED: DigitalSignature CredentialMac
79 67         3634 if ($self->{_nodeName} eq 'Sender') {
80 67 100       2273 $node->add('UserAgent', $Business::cXML::USERAGENT);
81             } elsif (ref $self->{contact}) {
82 67 100       451 $node->add('Correspondent', undef, preferredLanguage => $self->{lang})
    100          
83 22         71 ->add($self->{contact}->to_node($node))
84             ;
85             };
86 1         4 return $node;
87             }
88              
89 67         831 =item C<B<domain>>
90              
91             Mandatory, default: C<NetworkId>
92              
93             =item C<B<id>>
94              
95             Mandatory
96              
97             =item C<B<type>>
98              
99             Optional, expected to be C<undef> (default) or C<marketplace>
100              
101             =item C<B<lang>>
102              
103             Optional, in outgoing messages it is only used if contact information is defined.
104              
105             =item C<B<contact>>
106              
107             Optional, L<Business::cXML::Contact> object
108              
109             =item C<B<_note>>
110              
111             Private note. It will be lost in conversion back to cXML. Intended to help
112             you store your own representation of the remote company during processing.
113              
114             =back
115              
116             =head3 C<Sender> adds:
117              
118             =over
119              
120             =item C<B<useragent>>
121              
122             Mandatory
123              
124             =item C<B<secret>>
125              
126             Optional
127              
128             =back
129              
130             =head1 AUTHOR
131              
132             Stéphane Lavergne L<https://github.com/vphantom>
133              
134             =head1 ACKNOWLEDGEMENTS
135              
136             Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
137              
138             =head1 COPYRIGHT & LICENSE
139              
140             Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
141              
142             Permission is hereby granted, free of charge, to any person obtaining a copy
143             of this software and associated documentation files (the "Software"), to deal
144             in the Software without restriction, including without limitation the rights
145             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
146             copies of the Software, and to permit persons to whom the Software is
147             furnished to do so, subject to the following conditions:
148              
149             The above copyright notice and this permission notice shall be included in all
150             copies or substantial portions of the Software.
151              
152             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
153             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
154             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
155             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
156             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
157             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
158             SOFTWARE.
159             =cut
160              
161             1;