Catalyst-TraitFor-Controller-Ping

 view release on metacpan or  search on metacpan

lib/Catalyst/TraitFor/Controller/Ping.pm  view on Meta::CPAN

package Catalyst::TraitFor::Controller::Ping;
our $VERSION = '0.001';

#ABSTRACT: Provides a ping action for consuming controllers

use MooseX::MethodAttributes::Role;
use namespace::autoclean;
use Try::Tiny;


has model_name => (isa => 'Str', is => 'ro', predicate => 'has_model_name', clearer => '_clear_model_name', writer => '_set_model_name');


has model_method => (isa => 'Str', is => 'ro', predicate => 'has_model_method', clearer => '_clear_model_method', writer => '_set_model_method');


has model_method_arguments => (isa => 'ArrayRef', is => 'ro', predicate => 'has_model_method_arguments', clearer => '_clear_model_method_arguments', writer => '_set_model_method_arguments');


sub ping :Local 
{
    my ($self, $c) = @_;
    
    if($self->has_model_name)
    {
        my $model = $c->model($self->model_name);

        if(!defined($model))
        {
            $c->error("Unable to find model '${\$self->model_name}'");
            $c->detach();
        }
        elsif($self->has_model_method)
        {
            my $args;

            if($self->has_model_method_arguments)
            {
                $args = $self->model_method_arguments;
            }

            try 
            {
                $model->${\$self->model_method}(@$args);
            }
            catch
            {
                $c->error("Problem calling '${\$self->model_method}' on '${\$self->model_name}': $_");
                $c->detach();
            }
        }
    }
}

1;


=pod

=head1 NAME

Catalyst::TraitFor::Controller::Ping - Provides a ping action for consuming controllers

=head1 VERSION

version 0.001

=head1 SYNOPSIS



( run in 1.975 second using v1.01-cache-2.11-cpan-39bf76dae61 )