File Coverage

blib/lib/Apache/Sling/UserUtil.pm
Criterion Covered Total %
statement 83 83 100.0
branch 32 32 100.0
condition n/a
subroutine 16 16 100.0
pod 10 10 100.0
total 141 141 100.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2              
3             package Apache::Sling::UserUtil;
4              
5 3     3   27385 use 5.008001;
  3         13  
  3         134  
6 3     3   20 use strict;
  3         5  
  3         99  
7 3     3   19 use warnings;
  3         11  
  3         295  
8 3     3   20 use Carp;
  3         7  
  3         294  
9 3     3   496 use Apache::Sling::URL;
  3         6  
  3         144  
10              
11             require Exporter;
12              
13 3     3   17 use base qw(Exporter);
  3         5  
  3         3006  
14              
15             our @EXPORT_OK = ();
16              
17             our $VERSION = '0.27';
18              
19             #{{{sub add_setup
20              
21             sub add_setup {
22 6     6 1 171 my ( $base_url, $act_on_user, $act_on_pass, $properties ) = @_;
23 6 100       22 if ( !defined $base_url ) { croak 'No base url defined to add against!'; }
  1         27  
24 5 100       14 if ( !defined $act_on_user ) { croak 'No user name defined to add!'; }
  2         41  
25 3 100       8 if ( !defined $act_on_pass ) {
26 1         12 croak "No user password defined to add for user $act_on_user!";
27             }
28 2         8 my $property_post_vars =
29             Apache::Sling::URL::properties_array_to_string($properties);
30 2         9 my $post_variables =
31             "\$post_variables = [':name','$act_on_user','pwd','$act_on_pass','pwdConfirm','$act_on_pass'";
32 2 100       5 if ( $property_post_vars ne q{} ) {
33 1         3 $post_variables .= ",$property_post_vars";
34             }
35 2         3 $post_variables .= ']';
36 2         16 return "post $base_url/system/userManager/user.create.html $post_variables";
37             }
38              
39             #}}}
40              
41             #{{{sub add_eval
42             # Return true if the return code is 200 or 201
43             # to support Sakai Nakamura using the more correct
44             # 201 "Created" return code:
45              
46             sub add_eval {
47 1     1 1 3 my ($res) = @_;
48 1         1 return ( ${$res}->code =~ /^20(0|1)$/x );
  1         5  
49             }
50              
51             #}}}
52              
53             #{{{sub change_password_setup
54              
55             sub change_password_setup {
56 7     7 1 514 my ( $base_url, $act_on_user, $act_on_pass, $new_pass, $new_pass_confirm ) =
57             @_;
58 7 100       19 if ( !defined $base_url ) { croak 'No base url defined!'; }
  1         11  
59 6 100       15 if ( !defined $act_on_user ) {
60 2         22 croak 'No user name defined to change password for!';
61             }
62 4 100       8 if ( !defined $act_on_pass ) {
63 1         11 croak "No current password defined for $act_on_user!";
64             }
65 3 100       8 if ( !defined $new_pass ) {
66 1         12 croak "No new password defined for $act_on_user!";
67             }
68 2 100       6 if ( !defined $new_pass_confirm ) {
69 1         11 croak "No confirmation of new password defined for $act_on_user!";
70             }
71 1         6 my $post_variables =
72             "\$post_variables = ['oldPwd','$act_on_pass','newPwd','$new_pass','newPwdConfirm','$new_pass_confirm']";
73             return
74 1         7 "post $base_url/system/userManager/user/$act_on_user.changePassword.html $post_variables";
75             }
76              
77             #}}}
78              
79             #{{{sub change_password_eval
80              
81             sub change_password_eval {
82 1     1 1 2 my ($res) = @_;
83 1         3 return ( ${$res}->code eq '200' );
  1         5  
84             }
85              
86             #}}}
87              
88             #{{{sub delete_setup
89              
90             sub delete_setup {
91 4     4 1 429 my ( $base_url, $act_on_user ) = @_;
92 4 100       16 if ( !defined $base_url ) {
93 1         12 croak 'No base url defined to delete against!';
94             }
95 3 100       10 if ( !defined $act_on_user ) { croak 'No user name defined to delete!'; }
  2         24  
96 1         3 my $post_variables = '$post_variables = []';
97             return
98 1         8 "post $base_url/system/userManager/user/$act_on_user.delete.html $post_variables";
99             }
100              
101             #}}}
102              
103             #{{{sub delete_eval
104              
105             sub delete_eval {
106 1     1 1 3 my ($res) = @_;
107 1         2 return ( ${$res}->code eq '200' );
  1         5  
108             }
109              
110             #}}}
111              
112             #{{{sub exists_setup
113              
114             sub exists_setup {
115 4     4 1 411 my ( $base_url, $act_on_user ) = @_;
116 4 100       16 if ( !defined $base_url ) {
117 1         10 croak 'No base url to check existence against!';
118             }
119 3 100       10 if ( !defined $act_on_user ) {
120 2         24 croak 'No user to check existence of defined!';
121             }
122 1         7 return "get $base_url/system/userManager/user/$act_on_user.tidy.json";
123             }
124              
125             #}}}
126              
127             #{{{sub exists_eval
128              
129             sub exists_eval {
130 2     2 1 5 my ($res) = @_;
131 2         3 return ( ${$res}->code eq '200' );
  2         9  
132             }
133              
134             #}}}
135              
136             #{{{sub update_setup
137              
138             sub update_setup {
139 4     4 1 476 my ( $base_url, $act_on_user, $properties ) = @_;
140 4 100       33 if ( !defined $base_url ) {
141 1         17 croak 'No base url defined to update against!';
142             }
143 3 100       12 if ( !defined $act_on_user ) { croak 'No user name defined to update!'; }
  1         14  
144 2         8 my $property_post_vars =
145             Apache::Sling::URL::properties_array_to_string($properties);
146 2         5 my $post_variables = '$post_variables = [';
147 2 100       7 if ( $property_post_vars ne q{} ) {
148 1         2 $post_variables .= "$property_post_vars";
149             }
150 2         4 $post_variables .= ']';
151             return
152 2         16 "post $base_url/system/userManager/user/$act_on_user.update.html $post_variables";
153             }
154              
155             #}}}
156              
157             #{{{sub update_eval
158              
159             sub update_eval {
160 1     1 1 432 my ($res) = @_;
161 1         2 return ( ${$res}->code eq '200' );
  1         5  
162             }
163              
164             #}}}
165              
166             1;
167              
168             __END__