Re: [Catalyst] subclassing Catalyst::Controller::HTML::FormFu
Am Samstag, 17. Januar 2009 12:06:33 schrieb Carl Franks: 2009/1/16 Markus Holzer markus.hol...@dmk-internet.com: Hi. I have created a subclass Catalyst::Controller::HTML::FormFu because I want to override the load_form() method. I *think* I have done it right, but it doesn't work. The load_form method is never called, but FormFu still works. What am I doing wrong? Hi Markus, I think you've been confused by the documentation which gives an example of FormMethod('load_form') as a way to call a method in your own controller, to return a form. If that's all you want to do, you don't need to sub class, just make sure that you use FormMethod() instead of FormConfig(), and that the load_form() method is in your controller class. The reason it's not currently working, is there's no load_form() method anywhere in the FormFu controller code, so nothing's calling it. An example of what I think you should be doing: package Superclix::Controller::Partnerprogramm; use strict; use warnings; use parent 'Catalyst::Controller'; sub load_form { my ($self, $c) = @_; # returns a HTML::FormFu object # can get an empty form to start with using $c-form; } sub neu : Local : FormMethod('load_form') { my ($self, $c) = @_; my $form = $c-stash-{form}; } Cheers, Carl ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ I don't want to work with an empty form. I want to get the form as created by formconfig and add some things to it. That's why I think subclassing is the way to go. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] subclassing Catalyst::Controller::HTML::FormFu
Hi. I have created a subclass Catalyst::Controller::HTML::FormFu because I want to override the load_form() method. I *think* I have done it right, but it doesn't work. The load_form method is never called, but FormFu still works. What am I doing wrong? Code: package Superclix::FormFuController; use strict; use warnings; use parent 'Catalyst::Controller::HTML::FormFu'; sub load_form { die (subclassed!); # more code } 1; It is used as follows: package Superclix::Controller::Partnerprogramm; use warnings; use strict; use parent qw(Superclix::FormFuController Superclix::SecureBaseController); sub neu : Local :FormConfig { my ($self, $c) = @_; # more code } 1; ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] API Versioning for Web Services
Bill Moseley schrieb: I'm looking for suggestions how to best support multiple API versions in an application. The API and web share many controller actions. As is not uncommon, actions available for the API are defined with an attribute: sub foo : Local XMLRPC( 'foo.get' ) { This is great for sharing code as often the API just exposes the same functionality as the web interface. When a new version of the web application is released then all web users see the new version at the same time. If an action in the new version expects an additional new parameter then the form posting to that action is modified at the same time. But, the API access to an application typically needs to be backward compatible to allow API users time to update their client applications with the newer requirements. So, it seems I would need multiple controller actions that are dispatched based on some version. Here's one idea I was kicking around: Say I have an existing controller action that is used by the web users, but also available as an XMLRPC API method: sub widget : Local XMLRPC( 'widget.get' ) { So in a new application version that controller action is changed and now requires a new parameter and returns new data. In the new version I want to support the new action but remain backward compatible. # fetch widget for web and API sub widget : Local XMLRPC( 'widget.get' ) Version( 2 ) { # deprecated to support old version of API sub widget_old : XMLRPC( 'widget.get' ) Version( 1 ) { Then in my custom API dispatcher match method I take the version into consideration when matching actions. Any better suggestions? You could make the version of the api being used a parameter of the request, falling back to the latest stable version if not present. Then, in your controller you use a simple dispatch table to call the function that should the lifting. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] RFC: Catalyst::Plugin::AutoValidate
Hello fellows, please bear with me, as this is my first contribution to Catalyst. From the pod: This Plugin validates request parameters against a specification in a file that directly relates to the requests path (like the .fb files when using Formbuilder). I'm curiuos of your opinions. Thank you, Holli ___ package Catalyst::Plugin::AutoValidate; use warnings; use strict; use YAML qw( LoadFile ); use Catalyst::Request; use Config::Validate; use Data::Dumper; use NEXT; our $VERSION = 0.01; sub prepare { my $class = shift; my $c = $class-NEXT::prepare( @_ ); my ( $config, $rpath, $spec_root, $spec_file, $validation_spec, $validator ); # config for this package $config= $c-config-{'Catalyst::Plugin::AutoValidate'}; # the request path $rpath = $c-request-path || $config-{index_spec} || 'index'; # root dir to look for specifications $spec_root = $config-{spec_root} || $c-{home}/cvspec; # spec file, deduced from path $spec_file = $spec_root/${rpath}..($config-{spec_extension}||cvs); # check if there are custom types configured if ( $config-{types} ) { # add to the validation module if ( ref( $config-{types} ) eq ARRAY ) { for ( @{$config-{types}} ) { Config::Validate::add_default_type(%$_); } } else { Config::Validate-add_default_type(%{$config-{types}}); } # move the types, so they won't get reprocessed another time $config-{xtypes} = delete $config-{types}; } # there is no matching spec file unless ( -e $spec_file ) { # that's ok or not, depending if we are paranoid $c-request-{validated} = $config-{paranoid} ? 0 : 1; } else { # load spec and validate the request against it $validation_spec = LoadFile( $spec_file ); $validator = Config::Validate-new( schema = $validation_spec ); # will die if validation fails eval { $validator-validate( config = $c-request-{parameters} ) }; unless ( $@ ) { $c-request-{validated} = 1; } else { $_ = $@; s/^.+?validate\(\): //; s/instead.+//; $c-request-{validation_error} = $_; $c-request-{validated} = 0; } } return $c; } 1; __DATA__ =head1 NAME Catalyst::Plugin::AutoValidate - Catalyst-Plugin for easy automatic validation of Request-Parameters =head1 VERSION Version 0.01 =head1 SYNOPSIS This Plugin validates request parameters against a specification in a file that directly relates to the requests path (like the .fb files when using Formbuilder). For the heavy lifting it uses Lhttp://search.cpan.org/~cmo/Config-Validate-0.2.6/lib/Config/Validate.pm; All validation options from that module are supported, as they get simply passed through. # application code package MyApp; use strict; use warnings; use Catalyst qw(AutoValidate); # MyApp::Controller::Root.pm # check parameters and display error message when # appropriate. Does NOT RUN THE CONTROLLER in that case, # otherwise proceed with controller sub begin : Private { my ($self, $c) = @_; $c-response-body( $c-request-{validation_error} ), $c-detach unless $c-request-{validated}; } # $c-{home}/cvspec/math/multiply.cvs (YAML) a: type: integer b: type: integer # MyApp::Controller::Math.pm sub multiply : Local { my ($self, $c) = @_; # this is safe because Autovalidate ensures both are integers $s-stash-{result} = $c-req-param('a') / $c-req-param('a') } =head1 CONFIGURATION __PACKAGE__-config( 'Catalyst::Plugin::AutoValidate' = { # root dir for looking up specifications spec_root = '', # when set, all requests without specification die paranoid = 0, # the name of the index spec (for empty paths) index_spec = 'index', # extension for spec-files spec_extension = 'cvs', # custom types types = [ # generator sub that generates a closure, could come in handy for lookups { name = 'custom', validate = sub { my $lookup = { exists = 1 }; return sub { die Not in lookup table! unless $lookup-{$_[1]} }; }-() }, # or easier sub { die Doesnt match! unless $_[1] =~ /[abc]/ }; ] } ); =cut =head1 AUTHOR Markus Holzer, C holli.holzer at googlemmail.com =head1 BUGS Please report any bugs or feature requests to Cbug-catalyst-plugin-AutoValidate at rt.cpan.org, or through the web interface at Lhttp://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-AutoValidate. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command
Re: [Catalyst] trouble with Catalyst::Controller::FormBuilder: form does not render correctly (no fields)
Can you post your .fb, template and controller code so we can see what the problem might be? [stephen] Of course, though all I did was trying the example from the pod, nothing fancy. code: !file: Infocenter/lib/Controller/Akte.pm package Infocenter::Controller::Akte; use strict; use warnings; use base qw(Catalyst::Controller::FormBuilder); # [snip] sub anlegen : Local Form { my ( $self, $c ) = @_; my $form = $self-formbuilder; if ( $form-submitted ) { if ( $form-validate ) { #send mail #forward thank you return $c-response-body(VALID FORM); } else { $c-stash-{ERROR} = INVALID FORM; $c-stash-{invalid_fields} = [ grep { !$_-validate } $form-fields ]; } } } 1; !file: Infocenter/root/forms/akte/anlegen.fb name: books_edit method: post fields: title: label: Book Title type: text size: 40 required: 1 author: label: Author's Name type: text size: 80 validate: NAME required: 1 isbn: label: ISBN# type: text size: 20 validate: /^(\d{10}|\d{13})$/ required: 1 desc: label: Description type: textarea cols: 80 rows: 5 submit: Save New Book ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] trouble with Catalyst::Controller::FormBuilder: form does not render correctly (no fields)
Fellow nerds, I've got a problem with Catalyst::Controller::FormBuilder. I'm doing exactly as advertised in the pod but the form refuses to render, or better said is its fields. The submit button is rendered with the correct caption (which is different from submit), hence the .fb file is found and loaded. And when i peek into $self-formbuilder-{fields} turns out the array is there, but empty. So the formbilder object is not correctly initialized, but I have no idea why. I've tried some variations, like Form(explicit/path) and different line endings (cr, lf, crlf) of the .fb file. no avail. i'd be grateful for suggestions. thank you ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] CatalystSites.org
Hi Stephen. Well, today I would like to announce the site launch. The site looks nice, but I find it a little bloatware to talk of 40+ sites, when it's obvious that a good part of them share the same layout and codebase and only differ in the content. I hope everyone finds the site to their liking and can find the time to register and post their Catalyst driven websites. I will, as soon as I have EmPiDri in a presentable state :) ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/