Skip to content

Instantly share code, notes, and snippets.

@jbearden0
Created November 13, 2015 17:01
Show Gist options
  • Save jbearden0/6a942c1ad7eb46fc05f0 to your computer and use it in GitHub Desktop.
Save jbearden0/6a942c1ad7eb46fc05f0 to your computer and use it in GitHub Desktop.
Create Fake Mojolicious Self
sub GetFakeSelf {
my $Permissions = { 1005 => 'VIEWONLY' };
my $Stash = { User => 999, Permissions => $Permissions };
my $Session = { ClientType => 1, OrgName => 'NONE', ID => 999 };
my $Tx = Mojo::Base->new();
my $App = Mojo::Base->new();
my $Log = Mojo::Log->new();
my $Req = Mojo::Log->new();
my $Self = Mojo::Base->new();
$Self->attr(tx => sub { return $Tx; } );
$Self->attr(app => sub { return $App; } );
$Self->attr(req => sub { return $Req; } );
$Self->attr(stash => sub { return $Stash; } );
$Self->attr(render => sub { return 0; } );
$Self->attr(session => sub { return $Session; } );
$Self->attr(render_not_found => sub { return print(@_); } );
$Self->tx->attr(remote_address => sub { return '127.0.0.1'; } );
$Self->app->attr(log => sub { return $Log; } );
$Self->app->attr(mode => sub { return 'fake'; } );
$Self->req->attr(is_secure => sub { return 0; } );
$Self->app->log->level('warn'); # debug, info, warn, error, or fatal
return $Self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment