-
-
Save Altai-man/546d99c3cbe4dfcd15b4ee9efa1f9ac4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6.d; | |
use Red::Model; | |
use Cro::HTTP::Session::Persistent; | |
role Cro::HTTP::Session::Red:ver<0.0.1>:auth<cpan:FCO>[::Model, Str :$new-url] does Cro::HTTP::Session::Persistent[Model] { | |
method load($session-id) { | |
# This one is extremely odd | |
# Technically, this method must have a return value `--> Model` | |
# But if you add that, it'll throw an exception of return type mismatch! | |
my $session = Model.^load: :sessionid($session-id); | |
note $session ~~ Model; # True, so must pass the return value check | |
note Model ~~ $session; # False | |
with $session { | |
return $_; | |
} else { | |
fail "Error loading session $session-id"; | |
} | |
} | |
method create(Str $session-id) { | |
# INSERTing a new record with a session-id | |
Model.^create: :sessionid($session-id); | |
} | |
method save($id, Model $session --> Nil) is rw { | |
# We need this because of: | |
# No data to be updated on object of type 'UserSession'. | |
# exception otherwise. | |
# I have no idea why it throws at all, I mean, | |
# if there are no updates - don't update, why an error? | |
# in any case, I don't know a way to ask for "Is there a data to update or not?" | |
# to replace this CATCH with a condition | |
CATCH { | |
default { | |
note .^name; | |
.note; | |
} | |
} | |
$session.^save; | |
} | |
method clear(--> Nil) { | |
# DELETE RECORDS WHERE EXPIRATION-DATE < now; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment