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 modified);
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 SL::YAML::Dump($self->get);
48 return $self if $self->{fetched};
49 return $self if !$self->{auth}->session_tables_present;
51 my $dbh = $self->{auth}->dbconnect;
52 my $query = qq|SELECT sess_value FROM auth.session_content WHERE (session_id = ?) AND (sess_key = ?)|;
53 ($self->{value}) = selectfirst_array_query($::form, $dbh, $query, $self->{auth}->get_session_id, $self->{key});
62 $self->{value} = SL::YAML::Load($self->{value}) unless $self->{parsed};
69 my ($self, $value) = @_;
71 return { simple => 1, data => $value } if $value !~ m/^---/;
73 my %params = ( simple => 1 );
75 my $data = SL::YAML::Load($value);
77 if (ref $data eq 'HASH') {
78 map { $params{$_} = $data->{$_} } keys %{ $data };
82 $params{data} = $data;
86 } or $params{data} = $value;