For my case, commenting the conditional and just leaving the block resolved
my issue.  I'm not sure what ramifications this has on other things or if
it helps to indicate what I may have done wrong elsewhere.  Any ideas?

[ In lib/perl5/Mojolicious/Renderer.pm ]

sub get_data_template {
  my ($self, $options) = @_;

  # Index DATA templates
  my $loader = Mojo::Loader->new;
*#  unless ($self->{index}) {*
    my $index = $self->{index} = {};
    for my $class (reverse @{$self->classes}) {
      $index->{$_} = $class for keys %{$loader->data($class)};
    }
*#  }*

  # Find template
  my $template = $self->template_name($options);
  return $loader->data($self->{index}{$template}, $template);
}




On Tue, Feb 11, 2014 at 4:27 PM, Stefan Adams
<[email protected]>wrote:

> 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.
>

-- 
*----------------------------------------------------------------*
*Keystone IT made the following notation*
*----------------------------------------------------------------*
*Email Confidentiality Notice: The information contained in this 
transmission is confidential, proprietary or privileged and may be subject 
to protection under the law, including the Health Insurance Portability and 
Accountability Act (HIPAA). *

*This message is for the sole use of the intended individual or entity to 
whom it is addressed. If you are not the intended recipient, you are 
notified that any use, distribution or copying of the message is strictly 
prohibited and may subject you to criminal or civil penalties. If you 
received this transmission in error, please contact the sender immediately 
at (314) 621-9500 and delete the material from all computers.*

-- 
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.

Reply via email to