| 1 | package WebDAO::Session; | ||||||||||||||||||||
| 2 | #$Id$ | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | WebDAO::Session - Session interface to protocol specific function | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 DESCRIPTION | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | Session interface to device(HTTP protocol) specific function | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =cut | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 4 | our $VERSION = '0.02'; | |||||||||||||||||||
| 16 | 4 | ▶ | use WebDAO; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 4 | ▶ | use WebDAO::CV; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 4 | ▶ | use WebDAO::Response; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 4 | ▶ | use Encode qw(encode decode is_utf8); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 4 | mk_attr( | |||||||||||||||||||
| 24 | Cgi_obj => undef, # request object | ||||||||||||||||||||
| 25 | Cgi_env => undef, | ||||||||||||||||||||
| 26 | U_id=> undef, | ||||||||||||||||||||
| 27 | Params => undef, | ||||||||||||||||||||
| 28 | _response_obj=> undef, #deprecated ? | ||||||||||||||||||||
| 29 | _is_absolute_url =>undef #deprecated ? | ||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | sub new { | ||||||||||||||||||||
| 33 | 4 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 34 | 4 | my $self = {}; | |||||||||||||||||||
| 35 | 4 | my $stat; | |||||||||||||||||||
| 36 | 4 | bless( $self, $class ); | |||||||||||||||||||
| 37 | 4 | $self->_init(@_); | |||||||||||||||||||
| 38 | 4 | return $self; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | sub _init { | ||||||||||||||||||||
| 43 | #Parametrs is realm | ||||||||||||||||||||
| 44 | 4 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
_init: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 45 | 4 | my %args = @_; | |||||||||||||||||||
| 46 | 4 | U_id $self undef; | |||||||||||||||||||
| 47 | Cgi_obj $self $args{cv} | ||||||||||||||||||||
| 48 | 4 | ▶ | || new WebDAO::CV::; #create default controller | ||||||||||||||||||
|
Condition33%1/3
$args{'cv'} || 'WebDAO::CV'->new
MC/DC0%0/2
$args{'cv'} || 'WebDAO::CV'->new
$args{'cv'}
'WebDAO::CV'->new
Truth table33%1/3
A || B
A= $args{'cv'}B= 'WebDAO::CV'->new
| |||||||||||||||||||||
| 49 | 4 | my $cv = $self->Cgi_obj; # Store Cgi_obj in local var | |||||||||||||||||||
| 50 | #create response object | ||||||||||||||||||||
| 51 | 4 | $self->_response_obj( | |||||||||||||||||||
| 52 | new WebDAO::Response:: | ||||||||||||||||||||
| 53 | cv => $cv | ||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 4 | Cgi_env $self ( | |||||||||||||||||||
| 57 | { | ||||||||||||||||||||
| 58 | url => $cv->url( -base => 1 ), #http://eng.zag | ||||||||||||||||||||
| 59 | path_info => $cv->url( -absolute => 1, -path_info => 1 ), | ||||||||||||||||||||
| 60 | path_info_elments => [], | ||||||||||||||||||||
| 61 | file => "", | ||||||||||||||||||||
| 62 | base_url => $cv->url( -base => 1 ), #http://base.com | ||||||||||||||||||||
| 63 | accept => $cv->accept, | ||||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 4 | Params $self ( $self->_get_params() ); | |||||||||||||||||||
| 68 | 4 | $self->Cgi_env->{path_info_elments} = $self->call_path($self->Cgi_env->{path_info}); | |||||||||||||||||||
| 69 | #set default header | ||||||||||||||||||||
| 70 | 4 | $cv->set_header("Content-Type" => 'text/html; charset=utf-8'); | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | #Get cgi params; | ||||||||||||||||||||
| 75 | sub _get_params { | ||||||||||||||||||||
| 76 | 7 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
_get_params: called CC=6 SCAR=28.7
| |||||||||||||||||||||
| 77 | 7 | my $_cgi = $self->Cgi_obj(); | |||||||||||||||||||
| 78 | 7 | my %params; | |||||||||||||||||||
| 79 | 7 | foreach my $i ( $_cgi->param() ) { | |||||||||||||||||||
| 80 | 0 | my @all = $_cgi->param($i); | |||||||||||||||||||
| 81 | 0 | foreach my $value (@all) { | |||||||||||||||||||
| 82 | 0 | ▶ | next if ref $value; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 0 | ▶ | $value = decode( 'utf8', $value ) unless is_utf8($value); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | 0 | ▶ | $params{$i} = scalar @all > 1 ? \@all : $all[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | 7 | return \%params; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | #Can be overlap if you choose another | ||||||||||||||||||||
| 92 | #alghoritm generate unique session ID (i.e cookie,http_auth) | ||||||||||||||||||||
| 93 | sub get_id { | ||||||||||||||||||||
| 94 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
get_id: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 95 | 0 | my $coo = U_id $self; | |||||||||||||||||||
| 96 | 0 | ▶ | return $coo if ($coo); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | 0 | return rand(100); | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =head2 call_path [$url] | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | Return ref to array of element from $url or from CGI ENV | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | sub call_path { | ||||||||||||||||||||
| 107 | 4 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
call_path: called CC=2 SCAR=10.9
Pod
documented
| |||||||||||||||||||||
| 108 | 4 | ▶ | my $url = shift || return $self->Cgi_env->{path_info_elments}; | ||||||||||||||||||
|
Condition50%1/2
shift() || (return $self->Cgi_env->{'path_info_elments'})
MC/DC0%0/1
shift() || (return $self->Cgi_env->{'path_info_elments'})
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 109 | 0 | $url =~ s%^/%%; | |||||||||||||||||||
| 110 | 0 | $url =~ s%/$%%; | |||||||||||||||||||
| 111 | 0 | return [ grep { defined $_ } split( /\//, $url ) ]; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =head2 set_absolute_url 1|0 | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | Set flag for build absolute pathes. Return previus value. | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | =cut | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | sub set_absolute_url { | ||||||||||||||||||||
| 122 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
set_absolute_url: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 123 | 0 | my $value = shift; | |||||||||||||||||||
| 124 | 0 | my $prev_value = $self->_is_absolute_url; | |||||||||||||||||||
| 125 | 0 | ▶ | $self->_is_absolute_url($value) if defined $value; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 126 | 0 | return $prev_value; | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | sub get_request { | ||||||||||||||||||||
| 130 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
get_request: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 131 | 0 | return $self->Cgi_obj; | |||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | #deprecated ??? use WebDAO::Engine::response | ||||||||||||||||||||
| 135 | sub response_obj { | ||||||||||||||||||||
| 136 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
response_obj: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 137 | 0 | return $self->_response_obj; | |||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | sub print { | ||||||||||||||||||||
| 141 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
print: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 142 | 0 | $self->Cgi_obj->print(@_); | |||||||||||||||||||
| 143 | } | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | sub ExecEngine { | ||||||||||||||||||||
| 146 | 0 | ▶ | my ( $self, $eng_ref,$path ) = @_; | ||||||||||||||||||
|
Subroutine
ExecEngine: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 147 | 0 | $eng_ref->_execute($self, $path); | |||||||||||||||||||
| 148 | 0 | $eng_ref->__send_event__("_sess_ended"); # TODO: deprecated : delete this line | |||||||||||||||||||
| 149 | 0 | $eng_ref->_commit(); | |||||||||||||||||||
| 150 | 0 | $eng_ref->_destroy; | |||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | sub destroy { | ||||||||||||||||||||
| 154 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
destroy: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 155 | 0 | $self->_response_obj(undef); | |||||||||||||||||||
| 156 | } | ||||||||||||||||||||
| 157 | 4 | 1; | |||||||||||||||||||
| 158 | __DATA__ | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | =head1 SEE ALSO | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | http://webdao.sourceforge.net | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | =head1 AUTHOR | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | Zahatski Aliaksandr, E<lt>zag@cpan.orgE<gt> | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | Copyright 2002-2012 by Zahatski Aliaksandr | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 173 | it under the same terms as Perl itself. | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | =cut | ||||||||||||||||||||
| 176 | |||||||||||||||||||||