On Tue, Apr 4, 2017 at 1:09 PM, iaw4 <[email protected]> wrote: > is this a bug or a feature?
There are no bugs with Mojolicious, not at this level -- trust me. :D $ perl myapp.pl get /page1 [Tue Apr 4 13:27:27 2017] [debug] GET "/page1" [Tue Apr 4 13:27:27 2017] [debug] Routing to a callback [Tue Apr 4 13:27:27 2017] [debug] Rendering inline template "d1081c4631f686c37138a7a9f3aca333" [Tue Apr 4 13:27:27 2017] [debug] 200 OK (0.00103s, 970.874/s) *hello from model: page 1 = everything ok* $ perl myapp.pl get /page2 [Tue Apr 4 13:28:13 2017] [debug] GET "/page2" [Tue Apr 4 13:28:13 2017] [debug] Routing to a callback [Tue Apr 4 13:28:13 2017] [debug] Rendering inline template "2a16bdd33c18ac712cb735c11b4975b5" [Tue Apr 4 13:28:13 2017] [debug] 200 OK (0.001008s, 992.063/s) *hello from model: page 2 = everything ok* $ !find find -type f ./myapp.pl ./lib/Question/Model/Model.pm ./lib/Question/Controller/Page2.pm ./lib/Question/Controller/Page1.pm ./lib/Mojolicious/Plugin/Mojolyst.pm $ find -type f | xargs cat *./myapp.pl <http://myapp.pl>* #!/usr/bin/env perl use lib 'lib'; use lib '.'; use Mojolicious::Lite; plugin Mojolyst => {controllers => 'Question::Controller'}; app->start(); *./lib/Question/Model/Model.pm* package Question::Model::Model; *# You missed this -- this is probably your main issue with respect to all of your Model questions* use strict; *# You might want to export your subroutines* *# I personally prefer to use Mojo::Base and access the sub thru an object* sub frommodel { return "hello from model"; } 1; *./lib/Question/Controller/Page2.pm* package Question::Controller::Page2; use Mojolicious::Lite; use Question::Model::Model; get '/page2' => sub { my $c = shift; *# This is long-winded because Question::Model::Model isn't exporting any functions* my $formmodel = Question::Model::Model::frommodel(); $c->stash(formmodel => $formmodel); *# Just throwing this in here so you can see passing it to your template* $c->render(inline => '<%= $formmodel %>: page 2 = everything ok'); }; 1; *./lib/Question/Controller/Page1.pm* package Question::Controller::Page1; use Mojolicious::Lite; use Question::Model::Model; get '/page1' => sub { my $c = shift; *# This is long-winded because Question::Model::Model isn't exporting any functions* my $formmodel = Question::Model::Model::frommodel(); $c->stash(formmodel => $formmodel); *# Just throwing this in here so you can see passing it to your template* $c->render(inline => '<%= $formmodel %>: page 1 = everything ok'); }; 1; *./lib/Mojolicious/Plugin/Mojolyst.pm* package Mojolicious::Plugin::Mojolyst; use Mojo::Base 'Mojolicious::Plugin'; use Mojo::Loader qw/find_modules load_class/; sub register { my ($self, $app, $conf) = @_; # Discover controllers for my $class ( find_modules $conf->{controllers} ) { # Steal children my $e = load_class $class; my @children = @{$class->new->routes->children}; $app->routes->add_child($_) for @children; # Make DATA sections accessible push @{$app->static->classes}, $class; push @{$app->renderer->classes}, $class; } } 1; -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
