Jifty/Object.pm

filter: Statementstmt 25.0% 10 / 40 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 42.8% 3 / 7 Podpod 100% 2 / 2 totaltotal 15.0% 15 / 100 CC 19 SCAR 51.7
CC
19
Cov
12%
_get_current_user
272.0
current_user
12.0
log
6.0
CRAP 176.2
« Jifty/Web/Form/Clickable.pm ↑ Summary Jifty/Action/Record.pm »
1 113 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 113 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Jifty::Object;
5  
6 113 ▶use Log::Log4perl ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Jifty::Object - Base class for most of Jifty's objects
11  
12 =head1 DESCRIPTION
13  
14 C<Jifty::Object> is the superclass of most of Jifty's objects. It is
15 used to provide convenient accessors to important global objects like
16 the database handle or the logger object, while still allowing
17 individual classes to overload these methods.
18  
19 We ought to be able to mix-in C<Jifty::Object> with any other class;
20 thus, we will not define C<new> or C<_init> in C<Jifty::Object>. We
21 do assume, however, that C<$self> is a blessed hash reference.
22  
23 =head1 METHODS
24  
25 =head2 current_user [USER]
26  
27 Gets/sets a user for the current user for this object. You often do
28 not need to call this explicitly; Jifty will inspect your caller's
29 C<current_user>, and so on up the call stack.
30  
31 =cut
32  
33  
34 0 ▶sub current_user {
Subroutine current_user: not called CC=3 SCAR=24.8
Pod documented
35 0 my $self = shift;
36 0 ▶ unless (ref($self)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 0 0 0
37 0 Carp::cluck("Called current_user as a class method! This has no chance of working. Fix your code.");
38 }
39 0 ▶ $self->{'_current_user'} = shift if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
40 0 return($self->{'_current_user'});
41 }
42  
43 =head2 PRIVATE _get_current_user
44  
45 Takes the ARGS paramhash passed to _init.
46 Find the current user. First, try to see if it's explicit.
47 After that, check the caller's current_user. After that, look
48 at Jifty->web->current_user
49  
50 Fills in current_user with that value
51  
52 =cut
53  
54  
55 0 ▶sub _get_current_user {
Subroutine _get_current_user: not called CC=16 SCAR=56.1
56 0 my $self = shift;
57 0 my %args = (@_);
58  
59 0 ▶ return if ( ref($self) && $self->current_user );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self and $self->current_user 0 0 0
Condition0%0/3
ref $self and $self->current_user
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self and $self->current_user
ref $self $self->current_user
Truth table0%0/3
A and B
A= ref $selfB= $self->current_user
ABresult
0X0
100
111
60  
61 0 ▶ if ( $args{'current_user'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"current_user"}) 0 0 0
62 0 return $self->current_user( $args{'current_user'} );
63 }
64  
65 0 my $cu;
66  
67 # Mason introduces a DIE handler that generates a mason exception
68 # which in turn generates a backtrace. That's fine when you only
69 # do it once per request. But it's really, really painful when you do it
70 # often, as is the case with fragments
71 #
72 0 local $SIG{__DIE__} = 'DEFAULT';
73 0 eval {
74 package DB;
75  
76 0 my $depth = 2;
77 0 ▶ while ( not $cu and $depth < 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $cu and $depth < 10) 0 0 0
Condition0%0/3
not $cu and $depth < 10
!ll&&!rl&&r
000
MC/DC0%0/2
not $cu and $depth < 10
not $cu $depth < 10
Truth table0%0/3
not(A) and B
A= not $cuB= $depth < 10
ABresult
0X0
100
111
78 # get the caller in array context to populate @DB::args
79 0 my ($package) = CORE::caller( $depth++ );
80 0 ▶ last if defined $package and $package eq "HTML::Mason::Commands";
Branch: 1 branch
BranchTrueFalseTotal
if defined $package and $package eq "HTML::Mason::Commands" 0 0 0
Condition0%0/3
defined $package and $package eq "HTML::Mason::Commands"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $package and $package eq "HTML::Mason::Commands"
defined $package $package eq "HTML::Mason::Commands"
Truth table0%0/3
A and B
A= defined $packageB= $package eq "HTML::Mason::Commands"
ABresult
0X0
100
111
81 0 my $caller_self = $DB::args[0];
82 0 ▶ next unless ref($caller_self); #skip class methods;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $caller_self 0 0 0
83 0 ▶ next unless my $s = $caller_self->can('current_user');
Branch: 1 branch
BranchTrueFalseTotal
unless my $s = $caller_self->can("current_user") 0 0 0
84 0 ▶ next unless my $t = $s->($caller_self);
Branch: 1 branch
BranchTrueFalseTotal
unless my $t = &$s($caller_self) 0 0 0
85 0 ▶ next unless defined $t->id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t->id 0 0 0
86 0 $cu = $t;
87 }
88 };
89  
90 # Just return it if we're a cless method
91 0 ▶ return $cu || Jifty->web->current_user unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
Condition0%0/3
$cu || 'Jifty'->web->current_user
l!l&&r!l&&!r
000
MC/DC0%0/2
$cu || 'Jifty'->web->current_user
$cu 'Jifty'->web->current_user
Truth table0%0/3
A || B
A= $cuB= 'Jifty'->web->current_user
ABresult
1X1
011
000
92  
93 # If we found something, return it
94 0 ▶ return $self->current_user( $cu ) if $cu;
Branch: 1 branch
BranchTrueFalseTotal
if $cu 0 0 0
95  
96 # Fallback to web ui framework
97 0 ▶ return $self->current_user( Jifty->web->current_user ) if Jifty->web;
Branch: 1 branch
BranchTrueFalseTotal
if "Jifty"->web 0 0 0
98  
99 0 return undef;
100 }
101  
102  
103 0 ▶sub _handle {
Subroutine _handle: not called CC=1 SCAR=6.9
104 0 return Jifty->handle();
105 }
106  
107 =head2 log
108  
109 Returns a L<Log::Log4perl> logger object; the category of the logger
110 is the same as the class of C<$self>.
111  
112 =cut
113  
114 0 ▶sub log {
Subroutine log: not called CC=2 SCAR=17.9
Pod documented
115 0 my $self = shift;
116  
117 0 ▶ return Log::Log4perl->get_logger(ref($self) || $self);
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
118 }
119  
120  
121 113 1;
« Jifty/Web/Form/Clickable.pm ↑ Summary Jifty/Action/Record.pm »