From 4081337fabd0f5c0e75ccad0c6b79f075db3caaa Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Mon, 2 Nov 2009 07:44:53 +1300 Subject: [PATCH] Initial throw up --- dist.ini | 11 +++--- lib/Catalyst/Plugin/Spark/Form.pm | 66 +++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 lib/Catalyst/Plugin/Spark/Form.pm diff --git a/dist.ini b/dist.ini index 6063892..c1cc3ae 100644 --- a/dist.ini +++ b/dist.ini @@ -1,4 +1,4 @@ -name = +name = Catalyst-Plugin-Spark-Form author = Kent Fredric license = Perl_5 copyright_holder = Kent Fredric @@ -7,9 +7,9 @@ copyright_holder = Kent Fredric major = 0 minor = 1 year = 2009 -month = 10 -day = 26 -hour = 12 +month = 11 +day = 02 +hour = 07 time_zone = Pacific/Auckland [AllFiles] @@ -44,5 +44,6 @@ time_zone = Pacific/Auckland [UploadToCPAN] [Prereq] - +Moose = 0.92 +namespace::autoclean = 0.09 diff --git a/lib/Catalyst/Plugin/Spark/Form.pm b/lib/Catalyst/Plugin/Spark/Form.pm new file mode 100644 index 0000000..9a672c1 --- /dev/null +++ b/lib/Catalyst/Plugin/Spark/Form.pm @@ -0,0 +1,66 @@ +package Catalyst::Plugin::Spark::Form; + +# A simple plugin to make forms accessible quickly off the CTX. + +# $Id:$ +use strict; +use warnings; + +use Moose; +use namespace::autoclean; + +=head1 SYNOPSIS + + use Catalyst qw/ Spark::Form /; + + ... + + sub action { + my ( $self, $ctx, @rest ) = @_; + + $ctx->form('bar') # loads My::Project::Form::Bar or My::Project::F::Bar + + } + +=cut + +=head1 METHODS + +=head2 form + + $ctx->form( $formname ) + +=cut + +sub form { + my ( $ctx, $name, @args ) = @_; + + if ($name) { + my @result = $c->_comp_search_prefixes( $name, qw/Form F/ ); + if ( ref $name ) { + return map { $c->_filter_component( $_, @args ) } @result; + } + return $c->_filter_component( $result[0], @args ); + } + + return $c->component( $c->action->class ); + +} + +=head1 CREDITS + +Code thrown together by James Laver L. + +Code stolen from $c->controller. + +=cut + +=head1 DISCLAIMER + +The code mightn't work, but its not my fault if it doesn't. Will gladly accept patches. + +=cut + +1; + +