lib/OpenFrame/AppKit/Session.pm

filter: Statementstmt 100% 40 / 40 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 8 / 8 totaltotal 98.3% 61 / 62 CC 2 SCAR 1.5
CC
2
Cov
98%
generate_id
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« lib/OpenFrame/AppKit/Segment/DispatchOnURI.pm ↑ Summary lib/OpenFrame/AppKit.pm »
1 package OpenFrame::AppKit::Session;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Cache::FileCache;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION=3.03;
10  
11 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12 5 my $class = shift;
13 5 my $self = {};
14 5 bless $self, $class;
15 5 $self->init();
16 5 return $self;
17 }
18  
19 5 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
20 5 my $self = shift;
21 5 $self->generate_id;
22 }
23  
24 3 ▶sub id {
Subroutine id: called CC=1 SCAR=0.0
Pod documented
25 3 my $self = shift;
26 3 return $self->{_id};
27 }
28  
29 5 ▶sub generate_id {
Subroutine generate_id: called CC=2 SCAR=7.0
Pod documented
30 5 my $self = shift;
31 5 ▶ return $self->{_id} if exists $self->{_id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_id"} 0 5 5
32 5 my $id = substr(md5_hex(time() . md5_hex(time(). {}. rand(). $$)), 0, 16);
33 5 $self->{_id} = $id;
34 }
35  
36 1 ▶sub store {
Subroutine store: called CC=1 SCAR=0.0
Pod documented
37 1 my $self = shift;
38 1 Cache::FileCache->new()->set( $self->id, $self );
39 1 return $self->id;
40 }
41  
42 1 ▶sub fetch {
Subroutine fetch: called CC=1 SCAR=0.0
Pod documented
43 1 my $class = shift;
44 1 my $id = shift;
45 1 return Cache::FileCache->new()->get( $id );
46 }
47  
48 2 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
49 2 my $self = shift;
50 2 my $key = shift;
51 2 return $self->{ $key };
52 }
53  
54 1 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
Pod documented
55 1 my $self = shift;
56 1 my $key = shift;
57 1 $self->{ $key } = shift;
58 1 return $self;
59 }
60  
61 3 1;
62  
63 =head1 NAME
64  
65 OpenFrame::AppKit::Session - sessions for OpenFrame
66  
67 =head1 SYNOPSIS
68  
69 use OpenFrame::AppKit::Session;
70
71 my $session = OpenFrame::AppKit::Session->new();
72  
73 my $id = $session->id();
74 $session->store();
75  
76 my $restored = OpenFrame::AppKit::Session->fetch( $id );
77  
78 =head1 DESCRIPTION
79  
80 OpenFrame::AppKit::Session provides a session class that is capable of
81 being stored and restored from disk. The session expects you to treat
82 it as a standard HASH for all intents and purposes, but does allow you
83 to encapsulate that with the methods get and set for top level keys.
84  
85 =head1 METHODS
86  
87 =over 4
88  
89 =item * new
90  
91 The C<new()> method instantiates a new OpenFrame::AppKit::Session and returns
92 it.
93  
94 =item * init
95  
96 The C<init()> method provides initialization routines for OpenFrame::AppKit::Session
97  
98 =item * id
99  
100 The C<id()> method returns the sessions id
101  
102 =item * generate_id
103  
104 The C<generate_id()> method returns a new id, or the old id if it has already been generated.
105  
106 =item * store
107  
108 The C<store()> method serializes the session to disk. It returns the session id that can be
109 used to restore the session.
110  
111 =item * fetch
112  
113 The C<fetch()> method takes a session id as a parameter and returns a restored session from disk.
114 In the case that the session is unavailable it returns nothing.
115  
116 =item * get
117  
118 The C<get()> method simply returns a key as specified by the first parameter and returns its value.
119  
120 =item * set
121  
122 The C<set()> method simply sets a key value pair as specified by the first two parameters.
123  
124 =back
125  
126 =head1 SEE ALSO
127  
128 OpenFrame::AppKit::Segment::Sesssion
129  
130 =head1 AUTHOR
131  
132 James A. Duncan <jduncan@fotango.com>
133  
134 =head1 COPYRIGHT
135  
136 Copyright 2002 Fotango Ltd. All Rights Reserved
137  
138 This program is released under the same license as Perl itself.
139  
140 =cut
« lib/OpenFrame/AppKit/Segment/DispatchOnURI.pm ↑ Summary lib/OpenFrame/AppKit.pm »