Can I have DATA templates in a Mojolicious full app and can I have multiple
DATA templates in multiple modules where the modules inherit the rendering
method from a base class?
At line 58 of Mojolicious::Renderer I've put in say
Data::Dumper::Dumper($self->{index});
On the first call to a page after a server restart, I get this:
[Tue Feb 11 16:00:46 2014] [debug] Your secret passphrase needs to be
changed!!!
[Tue Feb 11 16:00:46 2014] [info] /emr_a/vitals
[Tue Feb 11 16:00:46 2014] [debug] *GET "/emr_a/vitals"*.
[Tue Feb 11 16:00:46 2014] [debug] Routing to *controller
"I70::EMR::A::Vitals" and action "index"*.
$VAR1 = undef;
[Tue Feb 11 16:00:46 2014] [debug] *Rendering template
"vitals/index.html.ep" from DATA section*.
$VAR1 = {
*'vitals/index.html.ep' => 'I70::EMR::A::Vitals',*
'layouts/pqgrid.html.ep' => 'I70::EMR'
};
On a follow up call to a page, I get this:
[Tue Feb 11 16:02:24 2014] [info] /emr_a/patients
[Tue Feb 11 16:02:24 2014] [debug] *GET "/emr_a/patients"*.
[Tue Feb 11 16:02:24 2014] [debug] Routing to *controller
"I70::EMR::A::Patients" and action "index"*.
$VAR1 = {
*'vitals/index.html.ep' => 'I70::EMR::A::Vitals',*
'layouts/pqgrid.html.ep' => 'I70::EMR'
};
[Tue Feb 11 16:02:24 2014] [debug] *Template "patients/index.html.ep" not
found*.
The second call should have 'patients/index.html.ep' in the index hash, not
vitals. The reason why it has the wrong one is that the 'unless' block at
L58 gives a value to index and on subsequent call index already has a value
and the block doesn't get executed.
*A) Should I be able to have DATA templates in more than one module where
the modules inherit the rendering method from a base class?*
*B) Am I doing it correctly? If not as below, how can I make a controller
which inherits from a base class pull the correct template from the routed
controller's DATA section?*
I've extracted what I think sufficiently illustrates the structure of how
I'm doing it.
$ cat lib/I70/EMR/A/Patients.pm
package I70::EMR::A::Patients;
use Mojo::Base 'I70::EMR::A';
# SNIP
1;
__DATA__
@@ patients/index.html.ep
% layout 'pqgrid';
%# SNIP
$ cat lib/I70/EMR/A/Vitals.pm
package I70::EMR::A::Vitals;
use Mojo::Base 'I70::EMR::A';
# SNIP
1;
__DATA__
@@ vitals/index.html.ep
% layout 'pqgrid';
%# SNIP
$ cat lib/I70/EMR/A.pm
package I70::EMR::A;
use Mojo::Base 'I70::EMR';
# SNIP
1;
$ cat lib/I70/EMR.pm
package I70::EMR;
use Mojo::Base 'Mojolicious::Controller';
# SNIP
*sub index {*
* my $self = shift;*
* push @{$self->app->renderer->classes}, __PACKAGE__ unless grep { $_ eq
__PACKAGE__ } @{$self->app->renderer->classes};*
* push @{$self->app->renderer->classes}, ref $self unless grep { $_ eq ref
$self } @{$self->app->renderer->classes};*
* $self->render(lc(((split /::/, ref $self))[-1]).'/index');*
*}*
1;
__DATA__
@@ layouts/pqgrid.html.ep
%# SNIP
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/groups/opt_out.