Catalyst::Enzyme::Controller - Enzyme Controller Base Class with


Catalyst-Enzyme documentation Contained in the Catalyst-Enzyme distribution.

Index


Code Index:

NAME

Top

Catalyst::Enzyme::Controller - Enzyme Controller Base Class with utility methods

SYNOPSIS

Top

See Catalyst::Enzyme

PROPERTIES

Top

METHODS

Top

run_safe($c, $sub, $fail_action, $fail_message, @rest)

Run the $sub->(@rest) ref inside an eval cage, and return 1.

Or, if $sub dies, set stash->{message} to $fail_message, stash->{error} to $@, log the error, shed a tear, and return 0.

class_to_moniker($class_name)

Return default moniker of $class_name.

Default is to take the last past of the $class_name, and split it on lower/uppercase boundaries.

If one can't be figured out, return the $class_name.

AUTHOR

Top

Johan Lindstrom <johanl ÄT cpan.org>

LICENSE

Top

This library is free software . You can redistribute it and/or modify it under the same terms as perl itself.


Catalyst-Enzyme documentation Contained in the Catalyst-Enzyme distribution.
package Catalyst::Enzyme::Controller;
use base 'Catalyst::Base';

our $VERSION = 0.10;



use strict;
use Data::Dumper;
use Carp;



sub run_safe {
    my ($self, $c, $sub, $fail_action, $fail_message, @rest) = @_;

    eval { $sub->() };
    $@ or return(1);

    my $message = $c->stash->{message} = $fail_message;
    $c->stash->{error} = $@;
    $c->log->error("$message: $@");
    $c->forward($fail_action);
    
    return(0);
}



sub class_to_moniker {
    my ($self) = shift;
    my ($class_name) = @_;

    $class_name =~ /::(\w+)$/ or return($class_name);
    my $moniker = $1;
    $moniker =~ s/([a-z])([A-Z])/$1 $2/g;
    
    return($moniker);
}





1;