Hi!  I'm glad you were able to figure that out and even using the more
advanced hook feature, but if I'm understanding your objective correctly, I
would advise that you follow the references I shared.  In essence, if I'm
reading it correctly, you are using a framework and then solving problems
on your own which are already solved by the framework.

I just want to make sure you get off to a good start with Mojolicious so
that you can reap the full benefits of the framework and not become
irritated that it's not doing things that you want easily -- essentially
questioning why you're using this framework in the first place.  :)

I'd recommend starting with a Mojolicious::Lite app.

Start with the Hello World
<https://mojolicious.org/perldoc/Mojolicious/Guides/Tutorial#Hello-World>
in the Tutorial.  And then expand it for your needs, perhaps like so:

#!/usr/bin/env perluse Mojolicious::Lite;
get '/:customer' => sub {
  my $c = shift;
  $c->render(inline => 'Hello, <%= param "customer" %>!');};

app->start;


Also, just to show some other equivalent ways to do the same thing:

#!/usr/bin/env perluse Mojolicious::Lite;
get '/:customer' => sub {
  my $c = shift;  my $customer = $c->param('customer');
  $c->render(inline => 'Hello, <%= $customer %>!', customer => $customer);};

app->start;


Also:

#!/usr/bin/env perluse Mojolicious::Lite;
get '/:customer' => sub {
  my $c = shift;  $c->render(inline => 'Hello, <%=
$c->param("customer") %>!');};

app->start;


On Wed, Jan 2, 2019 at 3:39 PM <[email protected]> wrote:

> Thanks Stefan.
>
>
> So, trying a different tack, I was able to parse the url of a request with
> a 'before_depatch' hook, and figure out what Customer Class should be used,
> before routing happens.
>
> Assuming the request url is /kwikemart/liquor/22, I figure out the
> customer name (kwikemart) like this:
>
>
> sub startup {
>     my $self = shift;
>     $self->req->url->path =~ m#^/(\w+)/.+#;
>     $customer = $1;}
>
>
> The question is, where to store this $customer, so I can use it to specify
> the correct route later? I still don't quite get how Mojo::Base Class work.
> Not sure how to correctly create custom attribute, that's local to each
> request, so it can be used within a $r->to() call.
>
>
>
>
>
> On Wednesday, January 2, 2019 at 4:34:20 AM UTC-6, [email protected]
> wrote:
>>
>> Hi. I want to route a request to a controller that's dynamically
>> constructed, base on a place holder in the url. To illustrate, I want do
>> something like the following:
>>
>> use Mojo::Base 'Mojolicious';
>>
>> sub startup {
>>
>> my $r = $self->routes;
>>
>>            my $route = $r->get('/:customer/boxs/:id');
>>
>>
>> [ somehow, extract the :customer holder into a variable $customer, then ]
>>
>>            $route->(
>>
>> controller => "$customer::boxs',
>>
>> action     => 'get_list',
>>
>> );
>>
>> }
>>
>>
>> I tried but can't seem to find way to this, and I'm not sure if this is
>> possible?
>> Some pointer is appreciated. Thanks.
>>
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to