| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # HTML::EP - A Perl based HTML extension. | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # Copyright (C) 1998 Jochen Wiedmann | ||||||||||||||||||||||||||||
| 7 | # Am Eisteich 9 | ||||||||||||||||||||||||||||
| 8 | # 72555 Metzingen | ||||||||||||||||||||||||||||
| 9 | # Germany | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # Phone: +49 7123 14887 | ||||||||||||||||||||||||||||
| 12 | # Email: joe@ispsoft.de | ||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | # All rights reserved. | ||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | # You may distribute this module under the terms of either | ||||||||||||||||||||||||||||
| 17 | # the GNU General Public License or the Artistic License, as | ||||||||||||||||||||||||||||
| 18 | # specified in the Perl README file. | ||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||
| 20 | ############################################################################ | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | require 5.004; | |||||||||||||||||||||||||||
| 23 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use HTML::EP (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use Storable (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | package HTML::EP::Session; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 2 | $HTML::EP::Session::VERSION = '0.1002'; | |||||||||||||||||||||||||||
| 32 | 2 | @HTML::EP::Session::ISA = qw(HTML::EP); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub _ep_session { | ||||||||||||||||||||||||||
|
Subroutine
_ep_session: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 35 | 0 | my $self = shift; my $attr = shift; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my $class = $attr->{'class'} || 'HTML::EP::Session::DBI'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'class'} || 'HTML::EP::Session::DBI'
MC/DC0%0/1
$attr->{'class'} || 'HTML::EP::Session::DBI'
$attr->{'class'}
Truth table0%0/2
A
A= $attr->{'class'}
| |||||||||||||||||||||||||||||
| 38 | 0 | my $c = $class . '.pm'; | |||||||||||||||||||||||||||
| 39 | 0 | $c =~ s/\:\:/\//g; | |||||||||||||||||||||||||||
| 40 | 0 | require $c; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | $self->{'_ep_session_code'} = $attr->{'hex'} ? 'h' : 's'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | my $session; | |||||||||||||||||||||||||||
| 45 | 0 | my $id = $attr->{'id'}; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | if (!$id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | # Create a new session | ||||||||||||||||||||||||||||
| 48 | 0 | require MD5; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $secret = ($attr->{'secret'} || 'this is secret?'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'secret'} || 'this is secret?'
MC/DC0%0/1
$attr->{'secret'} || 'this is secret?'
$attr->{'secret'}
Truth table0%0/2
A
A= $attr->{'secret'}
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $max_retries = $attr->{'max_retries'} || 5; | ||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'max_retries'} || 5
MC/DC0%0/1
$attr->{'max_retries'} || 5
$attr->{'max_retries'}
Truth table0%0/2
A
A= $attr->{'max_retries'}
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | for (my $i = 0; !$session && $i < $max_retries; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $session and $i < $max_retries
MC/DC0%0/2
not $session and $i < $max_retries
not $session
$i < $max_retries
Truth table0%0/3
not(A) and B
A= not $sessionB= $i < $max_retries
| |||||||||||||||||||||||||||||
| 52 | 0 | $id = MD5->hexhash(time() . {} . rand() . $$ . $secret); | |||||||||||||||||||||||||||
| 53 | 0 | $session = eval { $class->new($self, $id, $attr) }; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if (!$session) { die $@ } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||
| 57 | 0 | $session = $class->Open($self, $id, $attr); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | $self->{'_ep_session_id'} = $id; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | my $var = $attr->{'var'} || 'session'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'var'} || 'session'
MC/DC0%0/1
$attr->{'var'} || 'session'
$attr->{'var'}
Truth table0%0/2
A
A= $attr->{'var'}
| |||||||||||||||||||||||||||||
| 62 | 0 | $self->{'_ep_session_var'} = $var; | |||||||||||||||||||||||||||
| 63 | 0 | $self->{$var} = $session; | |||||||||||||||||||||||||||
| 64 | $self->print("Created session:\n", $self->Dump($session)) | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if $self->{'debug'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ''; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub _ep_session_store { | ||||||||||||||||||||||||||
|
Subroutine
_ep_session_store: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 70 | 0 | my $self = shift; my $attr = shift; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $id = ($attr->{'id'} || $self->{'_ep_session_id'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attr->{'id'} || $self->{'_ep_session_id'}
MC/DC0%0/2
$attr->{'id'} || $self->{'_ep_session_id'}
$attr->{'id'}
$self->{'_ep_session_id'}
Truth table0%0/3
A || B
A= $attr->{'id'}B= $self->{'_ep_session_id'}
| |||||||||||||||||||||||||||||
| 73 | or die "No session ID given"; | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my $var = $attr->{'var'} || $self->{'_ep_session_var'}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$attr->{'var'} || $self->{'_ep_session_var'}
MC/DC0%0/2
$attr->{'var'} || $self->{'_ep_session_var'}
$attr->{'var'}
$self->{'_ep_session_var'}
Truth table0%0/3
A || B
A= $attr->{'var'}B= $self->{'_ep_session_var'}
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | my $session = $self->{$var} or die "No such session: $var"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | $self->print("Storing session:\n", $self->Dump($session)) | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if $self->{'debug'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | $session->Store($self, $id, $attr->{'locked'}); | |||||||||||||||||||||||||||
| 79 | 0 | ''; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub _ep_session_item { | ||||||||||||||||||||||||||
|
Subroutine
_ep_session_item: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; my $attr = shift; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $id = ($attr->{'id'} || $self->{'_ep_session_id'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attr->{'id'} || $self->{'_ep_session_id'}
MC/DC0%0/2
$attr->{'id'} || $self->{'_ep_session_id'}
$attr->{'id'}
$self->{'_ep_session_id'}
Truth table0%0/3
A || B
A= $attr->{'id'}B= $self->{'_ep_session_id'}
| |||||||||||||||||||||||||||||
| 86 | or die "No session ID given"; | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my $var = $attr->{'var'} || $self->{'_ep_session_var'}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$attr->{'var'} || $self->{'_ep_session_var'}
MC/DC0%0/2
$attr->{'var'} || $self->{'_ep_session_var'}
$attr->{'var'}
$self->{'_ep_session_var'}
Truth table0%0/3
A || B
A= $attr->{'var'}B= $self->{'_ep_session_var'}
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $session = $self->{$var} or die "No such session: $var"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | my $items = $session->{'items'}; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | if (!$items) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | $items = $session->{'items'} = {}; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 0 | my $item = $attr->{'item'}; | |||||||||||||||||||||||||||
| 94 | 0 | my $num; | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($num = $attr->{'add'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $num = ($items->{$item} || 0) + $attr->{'add'}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$items->{$item} || 0
MC/DC0%0/1
$items->{$item} || 0
$items->{$item}
Truth table0%0/2
A
A= $items->{$item}
| |||||||||||||||||||||||||||||
| 97 | } else { | ||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $num = $attr->{'num'} || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'num'} || 0
MC/DC0%0/1
$attr->{'num'} || 0
$attr->{'num'}
Truth table0%0/2
A
A= $attr->{'num'}
| |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 0 | $items->{$item} = $num; | |||||||||||||||||||||||||||
| 101 | 0 | ''; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub _ep_session_delete { | ||||||||||||||||||||||||||
|
Subroutine
_ep_session_delete: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 105 | 0 | my $self = shift; my $attr = shift; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | my $id = ($attr->{'id'} || $self->{'_ep_session_id'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attr->{'id'} || $self->{'_ep_session_id'}
MC/DC0%0/2
$attr->{'id'} || $self->{'_ep_session_id'}
$attr->{'id'}
$self->{'_ep_session_id'}
Truth table0%0/3
A || B
A= $attr->{'id'}B= $self->{'_ep_session_id'}
| |||||||||||||||||||||||||||||
| 108 | or die "No session ID given"; | ||||||||||||||||||||||||||||
| 109 | 0 | ▶ | my $var = $attr->{'var'} || $self->{'_ep_session_var'}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$attr->{'var'} || $self->{'_ep_session_var'}
MC/DC0%0/2
$attr->{'var'} || $self->{'_ep_session_var'}
$attr->{'var'}
$self->{'_ep_session_var'}
Truth table0%0/3
A || B
A= $attr->{'var'}B= $self->{'_ep_session_var'}
| |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | my $session = $self->{$var} or die "No such session: $var"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | $session->Delete($self, $id); | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | undef $self->{'_ep_session_id'} unless $attr->{'id'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | ''; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 2 | 1; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||||||