Skip to content

Instantly share code, notes, and snippets.

@Logioniz
Last active August 29, 2015 14:18
Show Gist options
  • Save Logioniz/ce2b53c9647cf0204e81 to your computer and use it in GitHub Desktop.
Save Logioniz/ce2b53c9647cf0204e81 to your computer and use it in GitHub Desktop.
Model class with weaken App.
#!/usr/bin/perl
# Run with command perl 1.pl get /
package AAA;
use Scalar::Util 'weaken';
sub new {
my ($class, $app) = @_;
my $hash = {app => $app};
weaken $hash->{app};
return bless $hash, $class;
}
sub run_asd { shift->{app}->asd }
package main;
use strict;
use warnings;
use Data::Dumper;
use Mojolicious::Lite;
use Scalar::Util 'weaken';
helper asd => sub { return "\n\nzxc\n\n" };
get '/' => sub {
my $c = shift;
my $a = AAA->new($c->app);
$c->render(text => $a->run_asd);
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment