Skip to content
Permalink
Browse files

Added Wing->stash which allows variables that last only 1 request.

  • Loading branch information...
rizen committed Sep 26, 2019
1 parent b958f3c commit 00753d70b601e85e685266e7154e7aabf2b4f073
Showing with 57 additions and 0 deletions.
  1. +1 −0 CHANGES.txt
  2. +47 −0 lib/Wing.pm
  3. +5 −0 lib/Wing/Rest.pm
  4. +4 −0 lib/Wing/Web.pm
@@ -6,6 +6,7 @@ with respect to new features and compatibility changes.

2019-09-26
* Remove unneeded param from .call in wing.vue.js
* Added Wing->stash which allows variables that last only 1 request.

2019-09-23
* UTF-8 encode messages to Firebase, too.
@@ -77,6 +77,7 @@ if ($_config->get('dbic_trace')) {
$_db->storage->debugfh(IO::File->new($_config->get('dbic_trace'), 'w'));
}


=head2 db
Return a copy of a database handle for this object as a L<DBIx::Class> object
@@ -131,6 +132,52 @@ sub tenant_db {
return $class->tenant($name)->connect_to_database;
}

=head2 stash
Returns an object that let's you set variables that will last only the duration of a request (in a request based environment)
=head3 get(name)
Get a variable by name.
=head3 set(name,value)
Set a value by name. The value can even be complete data structures and objects since stash variables are never serialized and only last the request.
=head3 reset()
Destroys all stash variables.
=cut

{
package Wing::Stash;
our $stash = {};

sub new {
my $class = shift;
return bless { stash => {} }, $class;
}

sub get {
return $_[0]->{$_[1]};
}

sub set {
$_[0]->{$_[1]} = $_[2];
return $_[2];
}

sub reset {
$_[0]->{stash} = {};
}
}

sub stash {
return Wing::Stash->new;
}


# cache
die "'cache' directive missing from config file" unless $_config->get('cache');
my $_cachelog = $_config->get('cachelog');
@@ -203,6 +203,11 @@ register generate_all_relationships => sub {
}
};

# not sure this is entirely necessary, but just want to make sure it is absolutely per request
hook before => sub {
Wing->stash->reset();
};

hook before_serializer => sub {
my $response = shift;
my $content = $response->{content};
@@ -64,6 +64,10 @@ register get_admin_by_session_id => sub {
}
};

hook before => sub {
Wing->stash->reset();
};

hook before_error_init => sub {
my $error = shift;
if (ref $error->exception eq 'Ouch') {

0 comments on commit 00753d7

Please sign in to comment.
You can’t perform that action at this time.