forked from perl-spark/Catalyst-Plugin-Spark-Form
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4420123
commit 4081337
Showing
2 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<http://jameslaver.com>. | ||
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; | ||
|
||
|