[Catalyst] Regex dispatch type is deprecated

Craig Chant craig at homeloanpartnership.com
Wed Jul 8 09:14:30 GMT 2015


Hi Jon,

Does that mean we shouldn't be using : http://search.cpan.org/~phaylon/Catalyst-Controller-Constraints-0.10_02/lib/Catalyst/Controller/Constraints.pm

Either?

Craig.

-----Original Message-----
From: John Napiorkowski [mailto:jjn1056 at yahoo.com]
Sent: 07 July 2015 19:51
To: The elegant MVC web framework
Subject: Re: [Catalyst] Regex dispatch type is deprecated

Dmitry,

You can use the Regexp Dispatcher on CPAN, for legacy code.  There is no plan to stop supporting it, unless we hit a point where we can't support it when making required fixes to Catalyst.  I just wanted to remove it from Catalyst core such as to emphasis its no longer the approved approach and prevent people from writing new code with it.

If you are using the newest Catalyst, we added Type Constraint matching to Args and this should let you dispatch on regexp types in a very similar manner.  Take a look at


https://metacpan.org/pod/distribution/Catalyst-Runtime/lib/Catalyst/RouteMatching.pod#Using-type-constraints-in-a-controller
which has an example of using a regular expression type constraint generator is a way that functions similarly to how the old regexp worked.  For example:


package MyApp::Controller::User;

use Moose;
use MooseX::MethodAttributes;
use Types::Standard qw/StrMatch/;

extends 'Catalyst::Controller';

sub looks_like_a_date :Path('') Args(StrMatch[qr{\d\d-\d\d-\d\d\d\d}]) {
  my ($self, $c, $date) = @_;
}

__PACKAGE__->meta->make_immutable;


requires a URL like /user/11-11-2222
That is one approach, or you can create custom ActionRoles for special dispatch rule needs.  In general I think the new feature to add type constraint checks on Args and CaptureArgs gives you everything you had with regexp and more.  Feedback, and bug fix patches welcomed!

Jnap



On Tuesday, July 7, 2015 10:42 AM, Dmitry Karasik <dmitry at karasik.eu.org> wrote:



Hello all,

I'm upgrading an older Catalyst installation, and re-writing code that uses Regex/LocalRegex dispatchers. The rewriting is mostly for routes such as Regex('a-(\d+)-(\d+).png'), and I'm writing new code which basically does the same, but using :Args(1), manually matching the last part of url, and detaching to new route with matched parameters. This is not a problem, but I'm thinking that I must be not the only one having the same problem, and there must be a module on CPAN that dispatches execution using regexes, as a replacement. But Catalyst::DispatchType::Regex that seems to be the offical replacement, warns about the Regex/LocalRegex attributes are deprecated, which is confusing to me -- the feature was removed from the core, okay, but I still want to use it through a separate module, why then warn about deprecation again?

So basically my question is, what's the best recommended way to rewrite requests such as a-2-3.png, for example? Or, how could I rewrite these requests with chaining?

--
Thank you,
    Dmitry Karasik


_______________________________________________
List: Catalyst at 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/

_______________________________________________
List: Catalyst at 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/
This Email and any attachments contain confidential information and is intended solely for the individual to whom it is addressed. If this Email has been misdirected, please notify the author as soon as possible. If you are not the intended recipient you must not disclose, distribute, copy, print or rely on any of the information contained, and all copies must be deleted immediately. Whilst we take reasonable steps to try to identify any software viruses, any attachments to this e-mail may nevertheless contain viruses, which our anti-virus software has failed to identify. You should therefore carry out your own anti-virus checks before opening any documents. HomeLoan Partnership will not accept any liability for damage caused by computer viruses emanating from any attachment or other document supplied with this e-mail. HomeLoan Partnership reserves the right to monitor and archive all e-mail communications through its network. No representative or employee of HomeLoan Partnership has the authority to enter into any contract on behalf of HomeLoan Partnership by email. HomeLoan Partnership is a trading name of H L Partnership Limited, registered in England and Wales with Registration Number 5011722. Registered office: Pharos House, 67 High Street, Worthing, West Sussex, BN11 1DN. H L Partnership Limited is authorised and regulated by the Financial Conduct Authority.



More information about the Catalyst mailing list