1 package SL::Auth::SessionValue;
5 # Classes that overload stringification must be known before
6 # YAML::Load() is called.
7 use SL::Locale::String ();
9 use Scalar::Util qw(weaken);
15 my ($class, %params) = @_;
17 my $self = bless {}, $class;
19 map { $self->{$_} = $params{$_} } qw(auth key value auto_restore);
21 $self->{fetched} = exists $params{value};
22 $self->{parsed} = !$params{raw} && exists $params{value};
24 # delete $self->{auth};
25 # $::lxdebug->dump(0, "NEW", $self);
26 # $self->{auth} = $params{auth};
35 return $self->_fetch->_parse->{value};
41 local $YAML::Stringify = 1;
42 return YAML::Dump($self->get);
48 return $self if $self->{fetched};
50 my $dbh = $self->{auth}->dbconnect;
51 my $query = qq|SELECT sess_value FROM auth.session_content WHERE (session_id = ?) AND (sess_key = ?)|;
52 ($self->{value}) = selectfirst_array_query($::form, $dbh, $query, $self->{auth}->get_session_id, $self->{key});
61 $self->{value} = YAML::Load($self->{value}) unless $self->{parsed};
68 my ($self, $value) = @_;
70 return { simple => 1, data => $value } if $value !~ m/^---/;
72 my %params = ( simple => 1 );
74 my $data = YAML::Load($value);
76 if (ref $data eq 'HASH') {
77 map { $params{$_} = $data->{$_} } keys %{ $data };
81 $params{data} = $data;
85 } or $params{data} = $value;