hi stefan---thank you for all your help. it's still a bit bewildering to
me.
I have about 500 webpages, each about 10 lines of code and 10 lines of
template. my ultimate goal is to tell future users/maintainers of my
webapp (who will not know M) the following:
When you want to modify "/example", first do a 'find . | grep example.pm'.
then edit this file. it will look like
$ cat example.pm
## M preamble, never touch
sub example {
my $c= shift;
my $data= grabdata(...);
my $html= data2html($data);
}
__DATA__
example.html.ep
% layout 'site';
% title 'page2';
Your data is <%== $html %> .
They should not need to know anything about M, except for the template
syntax. (I may need to give them instructions about how to add a new page,
too.) They should not have to know about controllers, models, views,
hierarchies, directory organization, differences in M and M-Lite, testing,
and perhaps even perl itself. This is a "near zero" learning curve.
Otherwise, my project will have failed.
So far, I had thought that M::Lite was the way to go. It's minimalist,
which is great. I tried 'use example', to pull in example.pm, but I could
not make this work. if it did work, I would be done! This was my ideal
solution. Even the original main M-Lite script would be easy to understand
in the future, as it would just contain 500 use statements. if this could
be made to work, I would be eternally grateful for a working example.
---
Alas, I am happy to try anything if I can make it work. So, now I am
trying to get your full M example to work.
$ mojo generate app MyApp
$ cd my_app
$ rm templates/example/welcome.html.ep
## here I make some changes, so...
$ cat lib/MyApp/Controller/Example.pm
package MyApp::Controller::Example;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Loader 'data_section';
sub example {
my $self = shift;
$self->render(msg => 'Modded Example to the Mojolicious real-time web
framework!');
}
1;
__DATA__
@@ example.html.ep
Example.pm <%= $msg %>
Now I am stuck at a beginner's puzzle. I want to hook this into the URL
'/example'. I look at MyApp.pm, where I see
$r->get('/')->to('example#example');
The syntax was a bit baffling. I needed to understand what # means. After
searching the tutorial and growing, I did find it eventually in routing as
'*Controller classes are perfect for organizing code in larger projects.
There are more dispatch strategies, but because controllers are the most
commonly used ones they also got a special shortcut in the form
of controller#action**.*' ok, I presume this means that the first example
is the name of the file 'Example.pm', and the second example is the name of
the function. ok, so I should be set.
unfortunately, I seem to be only half set.
$ morbo script/my_app
gives me a befuddling error message. I see from the stash that sub example
in Example.pm was running. (Yeah!!) Alas, it also tells me that "Page not
found... yet!" This may require only a very trivial fix, but I have no
idea what.
Stefan, thanks for all your help. I apologize for the length of this
message. Part of this is to signal that I am taking my education seriously
here.
regards, /iaw
--
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.