File Coverage

blib/lib/WebService/Cmis/Agent/BasicAuth.pm
Criterion Covered Total %
statement 9 25 36.0
branch 0 4 0.0
condition n/a
subroutine 3 7 42.8
pod 4 4 100.0
total 16 40 40.0


line stmt bran cond sub pod time code
1             package WebService::Cmis::Agent::BasicAuth;
2              
3             =head1 NAME
4              
5             WebService::Cmis::Agent::BasicAuth - authenticate via HTTP basic auth
6              
7             =head1 DESCRIPTION
8              
9             This class implements authentication using HTTP basic authentication.
10             It will be used when no other authentication mechanism has been specified
11             for a client.
12              
13             my $client = WebService::Cmis::getClient(
14             url => "http://cmis.alfresco.com/service/cmis",
15             useragent => new WebService::Cmis::Agent::BasicAuth(
16             user => "user",
17             password => "password",
18             );
19             );
20            
21             my $repo = $client->getRepository;
22              
23             Parent class: L
24              
25             =cut
26              
27 1     1   4074 use strict;
  1         3  
  1         33  
28 1     1   6 use warnings;
  1         2  
  1         24  
29              
30 1     1   6 use WebService::Cmis::Agent ();
  1         2  
  1         256  
31             our @ISA = qw(WebService::Cmis::Agent);
32              
33             =head1 METHODS
34              
35             =over 4
36              
37             =item new(%params)
38              
39             Create a new WebService::Cmis::Agent::BasicAuth.
40              
41             See L for more options.
42              
43             Parameters:
44              
45             =over 4
46              
47             =item * user
48              
49             =item * password
50              
51             =back
52              
53             =cut
54              
55             sub new {
56 0     0 1   my ($class, %params) = @_;
57              
58 0           my $user = delete $params{user};
59 0           my $password = delete $params{password};
60              
61 0           my $this = $class->SUPER::new(%params);
62              
63 0           $this->{user} = $user;
64 0           $this->{password} = $password;
65              
66 0           return $this;
67             }
68              
69             =item login(%params)
70              
71             sets the user and password for the current user agent
72              
73             Parameters:
74              
75             =over 4
76              
77             =item * user
78              
79             =item * password
80              
81             =back
82              
83             =cut
84              
85             sub login {
86 0     0 1   my $this = shift;
87 0           my %params = @_;
88              
89 0 0         $this->{user} = $params{user} if defined $params{user};
90 0 0         $this->{password} = $params{password} if defined $params{password};
91             }
92              
93             =item logout()
94              
95             invalidates the user credentials
96              
97             =cut
98              
99             sub logout {
100 0     0 1   my $this = shift;
101              
102 0           $this->{user} = undef;
103 0           $this->{password} = undef;
104             }
105              
106             =item get_basic_credentials()
107              
108             overrides the method in LWP::UserAgent to implement the given authentication mechanism.
109              
110             =cut
111              
112             sub get_basic_credentials {
113 0     0 1   my ($this, $realm) = @_;
114              
115 0           return ($this->{user}, $this->{password});
116             }
117              
118             =back
119              
120              
121             =head1 COPYRIGHT AND LICENSE
122              
123             Copyright 2012-2013 Michael Daum
124              
125             This module is free software; you can redistribute it and/or modify it under
126             the same terms as Perl itself. See F.
127              
128             =cut
129              
130             1;