| 1 | package OurCal::Handler::CGI; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use CGI; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use CGI::Carp qw(fatalsToBrowser); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 2 | my $user_cookie_name = 'ourcal_user_cookie'; | |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | OurCal::Handler::CGI - the default, cgi based handler for OurCal | ||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | my $config = OurCal::Config->new( file => 'ourcal.conf' ); | ||||||||||||||||||||||||||||||||||
| 16 | my $handler = OurCal::Handler::CGI->new( config => $config ); | ||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | =head2 new <param[s]> | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | Requires a C<OurCal::Config> object passed in as the config param. | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 29 | 0 | my ($class, %opts) = @_; | |||||||||||||||||||||||||||||||||
| 30 | 0 | $opts{_cgi} = CGI->new; | |||||||||||||||||||||||||||||||||
| 31 | 0 | return bless \%opts, $class; | |||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub _get_default_date { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_default_date: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 35 | 0 | my ($mon, $year) = (localtime)[4,5]; | |||||||||||||||||||||||||||||||||
| 36 | 0 | my $default = ($year+1900)."-"; | |||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $default .= '0' if ($mon<9); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 38 | 0 | $default .= ($mon+1); | |||||||||||||||||||||||||||||||||
| 39 | 0 | return $default; | |||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | =head2 view | ||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | Get the name of the view we should be using | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub view { | ||||||||||||||||||||||||||||||||
|
Subroutine
view: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 49 | 0 | return $_[0]->_get_with_default('view', 'html'); | |||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | =head2 date | ||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | Returns the date | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | =cut | ||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub date { | ||||||||||||||||||||||||||||||||
|
Subroutine
date: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 60 | 0 | return $_[0]->_get_with_default('date', _get_default_date); | |||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | =head2 user | ||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | Returns the user as defined by HTTP Basic Auth, cookie or user CGI | ||||||||||||||||||||||||||||||||||
| 66 | param. | ||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub user { | ||||||||||||||||||||||||||||||||
|
Subroutine
user: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 71 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return undef if 'del_cookie' eq $self->mode; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return $self->{user} if defined $self->{user} && length($self->{user}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"user"} and length $self->{"user"}
MC/DC0%0/2
defined $self->{"user"} and length $self->{"user"}
defined $self->{"user"}
length $self->{"user"}
Truth table0%0/3
A and B
A= defined $self->{"user"}B= length $self->{"user"}
| |||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | 0 | $self->{_user_needed} = 0; | |||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 0 | my $user; | |||||||||||||||||||||||||||||||||
| 78 | 0 | my $tmp_user = $user = $self->param('user'); | |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | # first try auth | ||||||||||||||||||||||||||||||||||
| 81 | 0 | $user = $self->{_cgi}->remote_user; | |||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | goto SKIP_USER if defined $user && length($user); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $user and length $user
MC/DC0%0/2
defined $user and length $user
defined $user
length $user
Truth table0%0/3
A and B
A= defined $userB= length $user
| |||||||||||||||||||||||||||||||||||
| 83 | #print STDERR "Didn't find remote user\n"; | ||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | # now cookie | ||||||||||||||||||||||||||||||||||
| 86 | 0 | $user = $self->{_cgi}->cookie($user_cookie_name); | |||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | goto SKIP_USER if defined $user && length($user); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $user and length $user
MC/DC0%0/2
defined $user and length $user
defined $user
length $user
Truth table0%0/3
A and B
A= defined $userB= length $user
| |||||||||||||||||||||||||||||||||||
| 88 | #print STDERR "Didn't find remote cookie\n"; | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | # lastly, set that user is needed | ||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | SKIP_USER: | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $user and length $user
MC/DC0%0/2
defined $user and length $user
defined $user
length $user
Truth table0%0/3
A and B
A= defined $userB= length $user
| |||||||||||||||||||||||||||||||||||
| 93 | $user = undef unless defined $user && length($user); | ||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | $self->{_user_needed} = (defined $tmp_user && (!defined $user || $user ne $tmp_user)); | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
defined $tmp_user && (!defined($user) || $user ne $tmp_user)
not defined $user or $user ne $tmp_user
MC/DC0%0/3
defined $tmp_user && (!defined($user) || $user ne $tmp_user)
defined $tmp_user
not defined $user
$user ne $tmp_user
Truth table0%0/4
A && not(B) or C
A= defined $tmp_userB= not defined $userC= $user ne $tmp_user
| |||||||||||||||||||||||||||||||||||
| 95 | # and get it from CGI params | ||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $user = $tmp_user if defined $tmp_user && length($tmp_user); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tmp_user and length $tmp_user
MC/DC0%0/2
defined $tmp_user and length $tmp_user
defined $tmp_user
length $tmp_user
Truth table0%0/3
A and B
A= defined $tmp_userB= length $tmp_user
| |||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | #print STDERR "Didn't find cgi user\n" unless defined $user; | ||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||
| 100 | 0 | $self->{user} = $user; | |||||||||||||||||||||||||||||||||
| 101 | 0 | return $user; | |||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | =head2 mode | ||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | Get what mode we should be using | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub mode { | ||||||||||||||||||||||||||||||||
|
Subroutine
mode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 111 | 0 | return $_[0]->_get_with_default('mode', 'display'); | |||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub _get_with_default { | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_with_default: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 115 | 0 | my ($self, $name, $default) = @_; | |||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if (not defined $self->{$name}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | $self->{$name} = $self->param($name) || $default || undef; | ||||||||||||||||||||||||||||||||
|
Condition0%0/5
$self->param($name) || $default || undef
$self->param($name) or $default
MC/DC0%0/2
$self->param($name) || $default || undef
$self->param($name)
$default
Truth table0%0/3
A or B
A= $self->param($name)B= $default
| |||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||
| 119 | 0 | return $self->{$name}; | |||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | =head2 header <mime type> | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | Return what header we need to print out. | ||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||
| 127 | =cut | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub header { | ||||||||||||||||||||||||||||||||
|
Subroutine
header: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 130 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 131 | 0 | my $type = shift; | |||||||||||||||||||||||||||||||||
| 132 | 0 | my $cgi = $self->{_cgi}; | |||||||||||||||||||||||||||||||||
| 133 | 0 | my %vars; | |||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | $vars{"-type"} = $type if defined $type; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ('del_cookie' eq $self->mode) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 137 | 0 | my $cookie = $cgi->cookie(-name => $user_cookie_name, -value => '' ); | |||||||||||||||||||||||||||||||||
| 138 | 0 | $vars{"-cookie"} = $cookie; | |||||||||||||||||||||||||||||||||
| 139 | } elsif (defined $self->user) { | ||||||||||||||||||||||||||||||||||
| 140 | 0 | my $cookie = $cgi->cookie(-name => $user_cookie_name, -value => $self->user ); | |||||||||||||||||||||||||||||||||
| 141 | 0 | $vars{"-cookie"} = $cookie; | |||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||
| 143 | 0 | return $cgi->header(%vars); | |||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | =head2 link <span> | ||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||
| 151 | Make a link out a C<OurCal::Span> object | ||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | =cut | ||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub link { | ||||||||||||||||||||||||||||||||
|
Subroutine
link: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 156 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 157 | 0 | my $span = shift; | |||||||||||||||||||||||||||||||||
| 158 | 0 | my $date = $span->date; | |||||||||||||||||||||||||||||||||
| 159 | 0 | my $user = $self->user; | |||||||||||||||||||||||||||||||||
| 160 | 0 | my $url = "?"; | |||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | $url .= "date=${date}" unless $span->is_this_span && $span->isa("OurCal::Month"); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$span->is_this_span and $span->isa("OurCal::Month")
MC/DC0%0/2
$span->is_this_span and $span->isa("OurCal::Month")
$span->is_this_span
$span->isa("OurCal::Month")
Truth table0%0/3
A and B
A= $span->is_this_spanB= $span->isa("OurCal::Month")
| |||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | $url .= "&user=${user}" if $self->need_user; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | $url = "." if $url eq "?"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||
| 166 | 0 | return $url; | |||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | =head2 param <name> | ||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||
| 171 | Get a CGI parma with the given name | ||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub param { | ||||||||||||||||||||||||||||||||
|
Subroutine
param: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 176 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 177 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||||
| 178 | 0 | my $cgi = $self->{_cgi}; | |||||||||||||||||||||||||||||||||
| 179 | 0 | return $cgi->param($name); | |||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | =head2 need_user | ||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||
| 184 | Whether a link need to include a user param or not | ||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||
| 186 | =cut | ||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub need_user { | ||||||||||||||||||||||||||||||||
|
Subroutine
need_user: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 190 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 191 | 0 | return $self->{_user_needed}; | |||||||||||||||||||||||||||||||||
| 192 | #return defined $self->user; | ||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | 2 | 1; | |||||||||||||||||||||||||||||||||