blib/lib/Template/Plugin/Apache/SessionManager.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
↑ Summary
1 package Template::Plugin::Apache::SessionManager;
2  
3 0 ▶use Apache::SessionManager;
Subroutine BEGIN: called CC=1 SCAR=2.6
4 use Template::Plugin;
5 use vars qw( $VERSION );
6 use base qw( Template::Plugin );
7 use strict;
8  
9 $VERSION = '0.02';
10  
11 sub new {
12 my ($class, $context, @params) = @_;
13 my $session = Apache::SessionManager::get_session(Apache->request);
14 bless {
15 _CONTEXT => $context,
16 session => $session,
17 }, $class;
18 }
19  
20 sub get {
21 my $self = shift;
22 my @args = ref($_[0]) eq 'ARRAY' ? @{$_[0]} : @_;
23 if ( ! @args ) {
24 @args = keys %{$self->{session}};
25 }
26 my @ary;
27 foreach ( @args ) {
28 push @ary, $self->{session}->{$_};
29 }
30 return @ary;
31 }
32  
33 sub set {
34 my ($self, @args) = @_;
35 my $config = @args && ref $args[-1] eq 'HASH' ? pop(@args) : {};
36 foreach ( keys %$config ) {
37 # to avoid ovverride session special keys
38 next if /^_session/;
39 $self->{session}->{$_} = $config->{$_};
40 }
41 return '';
42 }
43  
44 sub delete {
45 my $self = shift;
46 my @args = ref($_[0]) eq 'ARRAY' ? @{$_[0]} : @_;
47 foreach ( @args ) {
48 # to avoid ovverride session special keys
49 next if /^_session/;
50 delete $self->{session}->{$_};
51 }
52 return '';
53 }
54  
55 sub destroy {
56 my $self = shift;
57 Apache::SessionManager::destroy_session(Apache->request);
58 }
59  
60 1;
61  
62 __END__
↑ Summary