| 1 | package DBR::Misc::Session; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 18 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 18 | ▶ | use base 'DBR::Common'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 18 | ▶ | use DateTime::TimeZone; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 18 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 17 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.7
Pod
undocumented
| |||||||||||||||
| 9 | 17 | my( $package ) = shift; | |||||||||||||
| 10 | |||||||||||||||
| 11 | 17 | my %params = @_; | |||||||||||||
| 12 | my $self = { | ||||||||||||||
| 13 | logger => $params{logger}, | ||||||||||||||
| 14 | admin => $params{admin} ? 1 : 0, | ||||||||||||||
| 15 | fudge_tz => $params{fudge_tz}, | ||||||||||||||
| 16 | 17 | ▶ | use_exceptions => $params{use_exceptions} ? 1 : 0, | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 17 | }; | ||||||||||||||
| 18 | |||||||||||||||
| 19 | 17 | bless( $self, $package ); | |||||||||||||
| 20 | |||||||||||||||
| 21 | 17 | ▶ | croak ('logger is required') unless $self->{logger}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | |||||||||||||||
| 23 | 17 | my $tz = ''; | |||||||||||||
| 24 | 17 | $self->{tzref} = \$tz; | |||||||||||||
| 25 | 17 | ▶ | $self->timezone('server') or confess "failed to initialize timezone"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | |||||||||||||||
| 27 | 17 | return $self; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | |||||||||||||||
| 31 | 17 | ▶ | sub timezone { | ||||||||||||
|
Subroutine
timezone: called CC=6 SCAR=19.4
Pod
undocumented
| |||||||||||||||
| 32 | 17 | my $self = shift; | |||||||||||||
| 33 | 17 | my $tz = shift; | |||||||||||||
| 34 | |||||||||||||||
| 35 | 0 | ▶ | return ${$self->{tzref}} unless defined($tz); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | |||||||||||||||
| 37 | 17 | ▶ | if($tz eq 'server' ){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | 17 | eval { | |||||||||||||
| 39 | 17 | my $tzobj = DateTime::TimeZone->new( name => 'local'); | |||||||||||||
| 40 | 0 | $tz = $tzobj->name; | |||||||||||||
| 41 | }; | ||||||||||||||
| 42 | 17 | ▶ | if($@){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | 17 | ▶ | if($self->{fudge_tz}){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | 17 | $self->_log( "Failed to determine local timezone. Fudging to UTC"); | |||||||||||||
| 45 | 17 | $tz = 'UTC'; | |||||||||||||
| 46 | }else{ | ||||||||||||||
| 47 | 0 | return $self->_error( "Failed to determine local timezone ($@)" ); | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | } | ||||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 17 | ▶ | DateTime::TimeZone->is_valid_name( $tz ) or return $self->_error( "Invalid Timezone '$tz'" ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | |||||||||||||||
| 54 | 17 | $self->_logDebug2('Set timezone to ' . $tz); | |||||||||||||
| 55 | |||||||||||||||
| 56 | 17 | return ${$self->{tzref}} = $tz; | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | 32 | ▶ | sub timezone_ref{ $_[0]->{tzref} } | ||||||||||||
|
Subroutine
timezone_ref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 59 | |||||||||||||||
| 60 | 46 | ▶ | sub is_admin{ $_[0]->{admin} } | ||||||||||||
|
Subroutine
is_admin: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 61 | 7 | ▶ | sub use_exceptions{ $_[0]->{use_exceptions} } | ||||||||||||
|
Subroutine
use_exceptions: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 62 | |||||||||||||||
| 63 | 17 | ▶ | sub _session { $_[0] } | ||||||||||||
|
Subroutine
_session: called CC=1 SCAR=0.0
| |||||||||||||||
| 64 | |||||||||||||||
| 65 | 1586 | ▶ | sub _log{ | ||||||||||||
|
Subroutine
_log: called CC=1 SCAR=0.0
| |||||||||||||||
| 66 | 1586 | my $self = shift; | |||||||||||||
| 67 | 1586 | my $message = shift; | |||||||||||||
| 68 | 1586 | my $mode = shift; | |||||||||||||
| 69 | |||||||||||||||
| 70 | 1586 | my ( undef,undef,undef, $method) = caller(2); | |||||||||||||
| 71 | 1586 | $self->{logger}->log($message,$method,$mode); | |||||||||||||
| 72 | |||||||||||||||
| 73 | 1586 | return 1; | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | |||||||||||||||
| 76 | 0 | ▶ | sub _directlog{ | ||||||||||||
|
Subroutine
_directlog: not called CC=1 SCAR=6.9
| |||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||
| 78 | 0 | my $message = shift; | |||||||||||||
| 79 | 0 | my $method = shift; | |||||||||||||
| 80 | 0 | my $mode = shift; | |||||||||||||
| 81 | |||||||||||||||
| 82 | 0 | $self->{logger}->log($message,$method,$mode) | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 18 | 1; | |||||||||||||