Skip to content

Commit

Permalink
updated growing guide with state variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 11, 2012
1 parent d25f32d commit a131c8c
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions lib/Mojolicious/Guides/Growing.pod
Expand Up @@ -234,21 +234,17 @@ logic related to matching usernames and passwords.

1;

A simple helper function can be registered with the method
L<Mojolicious/"helper"> to make our C<model> available to all actions and
templates.
A simple helper can be registered with the method L<Mojolicious/"helper"> to
make our C<model> available to all actions and templates.

#!/usr/bin/env perl
use Mojolicious::Lite;

use lib 'lib';
use MyUsers;

# Model object
my $users = MyUsers->new;

# Helper function returning our model object
helper users => sub { return $users };
# Helper returning our model object
helper users => sub { state $users = MyUsers->new };

# /?user=sri&pass=secr3t
any '/' => sub {
Expand Down Expand Up @@ -393,8 +389,7 @@ like this.
# Make signed cookies secure
app->secret('Mojolicious rocks');

my $users = MyUsers->new;
helper users => sub { return $users };
helper users => sub { state $users = MyUsers->new };

# Main login action
any '/' => sub {
Expand Down Expand Up @@ -509,8 +504,7 @@ actual action code needs to be changed.
my $self = shift;

$self->secret('Mojolicious rocks');
my $users = MyUsers->new;
$self->helper(users => sub { return $users });
$self->helper(users => sub { state $users = MyUsers->new });

my $r = $self->routes;

Expand Down Expand Up @@ -615,8 +609,7 @@ information.
my $self = shift;

$self->secret('Mojolicious rocks');
my $users = MyUsers->new;
$self->helper(users => sub { return $users });
$self->helper(users => sub { state $users = MyUsers->new });

my $r = $self->routes;
$r->any('/')->to('login#index')->name('index');
Expand Down

0 comments on commit a131c8c

Please sign in to comment.