SiteControl/User.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 75 CC 5 SCAR 17.1
CC
5
Cov
0%
logout
12.0
setAttribute
6.0
getAttribute
6.0
CRAP 5.5
1 package Apache::SiteControl::User;
2  
3 use 5.008;
4 use strict;
5 use warnings;
6 use Carp;
7  
8 our $VERSION = "1.0";
9  
10 # This object represents a transient view of a persistent user. The UserManager
11 # is responsible for loading/saving these things.
12 sub new($$$$) {
13 my $proto = shift;
14 my $username = shift;
15 my $sessionid = shift;
16 my $usermanager = shift;
17 my $class = ref($proto) || $proto;
18 my $this = { username => $username,
19 sessionid => $sessionid,
20 manager => $usermanager,
21 attributes => {} };
22 bless ($this, $class);
23 return $this;
24 }
25  
26 sub getUsername
27 {
28 my $this = shift;
29 return $this->{username};
30 }
31  
32 # user, request, name, value
33 sub setAttribute
34 {
35 my $this = shift;
36 my $r = shift;
37 my $name = shift;
38 my $value = shift;
39  
40 $this->{attributes}{$name} = $value;
41 eval("$this->{manager}" . '->saveAttribute($r, $this, $name)');
42 if($@) {
43 $r->log_error("ERROR! FAILED TO SAVE ATTRIBUTE. SESSION WILL NOT WORK: $@");
44 }
45 }
46  
47 sub getAttribute
48 {
49 my $this = shift;
50 my $name = shift;
51  
52 return $this->{attributes}{$name} if defined($this->{attributes}{$name});
53  
54 return undef;
55 }
56  
57 # user object, apache request
58 sub logout
59 {
60 my $this = shift;
61 my $r = shift;
62  
63 if(!defined($this) || !defined($r)) {
64 croak "INVALID CALL TO LOGOUT. You forgot to use OO syntax, or you forgot to pass the request object.";
65 }
66 eval("$this->{manager}" . '->invalidate($r, $this)');
67 if($@) {
68 $r->log_error("Logout failed: $@");
69 }
70 }
71  
72 1;
73  
74 __END__