Working Through a Catalyst View Rendering Problem

1 minute read

I’ve been adding some belated email notifications to UVFood and in the process I ran into a frustrating problem: it wasn’t working at all.

The email notifications are for things like messages people send through the contact form, new user signups, errors. After those are working I’m finally adding welcome emails, confirmation emails and eventually optional weekly summaries of changes to users’ favorites. UVFood is written in Perl using the Catalyst Framework and HTML::Mason for page rendering.

First of all, there are a lot of ways to send email. One that people opt for is to use Catalyst::View::Email. I don’t really see the point of it. Email sending seems more of an action to me than a view. Views are for rendering pages, but Catalyst::View::Email takes already-rendered text and then emails it somewhere.So instead of Catalyst::View::Email I decided to use Mail::SendEasy. Mail::SendEasy is, well, easy. Not a lot of fuss.

I’ve written templates for the messages I need to send using HTML::Mason, so I need to render these templates before I can send a message. This is where I was getting hung up.

My original code was:


    my $email_addr = $c->stash->{email_addr};

    my $v = $c->view('Mason');
    my $body = $v->render($c,
			            '/EmailMsgs/Text/AdminContact.mas');

    # notify the admin
    Util::send_email(to => '[email protected]',
		            from => '[email protected]',
	                 subject => 'Admin: New message',
		            msg => $body);

Frustratingly, this did not work. The message was mailed but it was empty.

Digging in I found that the render call was returning nothing.

I added debugging messages to Catalyst::View::Mason and realized it wasn’t even being called. I was trapped by a case of Catalyst’s overzealous and sometimes bizarre component matching. The fix is to fully qualify the view name, ie:


    my $v = $c->view('UVFoodApp::View::Mason');

Now I’m getting the correct component. Problem solved.

Updated: