three18ti has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks
I'm working on an internal application, I think calling it a blog "engine" is a bit too generous... I'm basically looking to build a very basic "web log" (literally, where we can log our work via web interface)
I'd like to be able to pull logs (they really aren't articles, more just "notes") based on the URL, e.g. http://address/$year/$month/$date/$title so http://address/2014/01/10/foo-bar-baz would pull the log from 10 Jan. 2014 about foo bar baz.
In something like dancer, this is really easy to do with route "placeholders", e.g.:
get '/:year/:month/:day' => sub { my $year = params->{year}; my $month = params->{month}; ... }
or
get '/*/*/*' => sub { my ($year, $month, $day) = splat; ... }
is there any way to do something similar in Catalyst? From my googling, it seems like "chained actions" are the way to go for this behavior, but they always seem like a black magic and make debugging a terrible pain in the arse... (maybe I'm just doing it wrong...?)
(I'm certainly not set on Catalyst, I've not done anything really advanced with either Dancer or Catalyst, for instance: https://github.com/three18ti/NetTools, but I can't for the life of me get Dancer to play nice with Moose (I'd prefer to deal with objects for everything since I'm using HTML::FormHandler and a couple other OO modules), and I like Catalyst better because I can break out my logic into multiple files instead of having everything in one gigantic file like Dancer requires (or well, seems to require, if I can break out my logic into multiple "controllers" like I can with Catalyst, then I'm doing it wrong. None of the dancer tutorials I've seen make use of this feature))
EDIT:
Maybe this is something: http://search.cpan.org/~ether/Catalyst-Manual-5.9007/lib/Catalyst/Manual/Intro.pod#URL_Path_Handling
But that seems like it would look for a specific string in that parameter, so I'd need 12 routes... e.g.,
sub jan : Regex('^01$') { my ($self, $context, $bar, $baz) = @_; } sub feb : Regex('^02$') { my ($self, $context, $bar, $baz) = @_; }
Which is not what I'm trying to accomplish. (There has to be a better way)
EDIT 2: maybe I should just use get parameters: http://search.cpan.org/~ether/Catalyst-Manual-5.9007/lib/Catalyst/Manual/Intro.pod#Query_Parameter_Processing
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [Catalyst] How do you handle "URL Parameters" (aka advanced "route matching")
by Theodore (Hermit) on Apr 03, 2014 at 13:11 UTC | |
by three18ti (Monk) on Apr 04, 2014 at 07:32 UTC | |
|
Re: [Catalyst] How do you handle "URL Parameters" (aka advanced "route matching")
by Your Mother (Archbishop) on Apr 04, 2014 at 17:36 UTC | |
|
Re: [Catalyst] How do you handle "URL Parameters" (aka advanced "route matching")
by Anonymous Monk on Apr 03, 2014 at 14:18 UTC | |
by three18ti (Monk) on Apr 04, 2014 at 07:34 UTC | |
|
Re: [Catalyst] How do you handle "URL Parameters" (aka advanced "route matching")
by Anonymous Monk on Apr 03, 2014 at 19:36 UTC | |
by three18ti (Monk) on Apr 04, 2014 at 07:35 UTC |