[Catalyst] How to trail the .html files in my control

Brandon Black blblack at gmail.com
Fri Feb 17 18:52:37 CET 2006


On 2/17/06, Vidya Sagar <vsagarkola at gmail.com> wrote:
> Thank you very much both Mr.Black and Mr.Wright for the answers u have
> given.but another issue is u can do only for one or two methods like 'list"
> but we are having lots of methods.so what shall we do.i will give my actual
> code just which will work for all the html files,when i used maypole  go
> through it and tell me what to do,
>
>  sub parse_path {
>
>          my $self = shift;
>          # remove the trailing .html for any path other than starting with
> /page/
>          $self->{path} =~ s/\.html$// if $self->{path} !~ /^page\//;
>
>          $self->SUPER::parse_path(@_);
>
>          # translate old paths into new paths
>          if($self->{path} =~ /cgi-bin\/store\/index.cgi/) {
>
>                  my $table = $self->{ar}->parms;
>
>                  if($table->get('page')) {
>                          if($table->get('page') =~ /officeprods.cgi/) {
>                                  $self->{table} = 'categories';
>                                  $self->{action} = 'officeproducts';
>                          }
>                          elsif($table->get('page') =~ /arrow-faq.htm/) {
>                                  $self->{path} = 'page/arrow-faq.htm';
>                          }
>                  }
>                  elsif($table->get('product') || $table->get('keywords')) {
>                          # search product category
>                          $self->{table} = 'product';
>                          $self->{action} = 'find';
>                          $table->set('keywords', $table->get('keywords')."
> ".$table->get('product'));
>                  }
>                  else { # catch all condition send the user to home page
>                          $self->{path} = 'frontpage';
>                  }
>
>                  $table->unset('exact_match');
>                  $table->unset('product');
>                  $table->unset('cat_row');
>                  $table->unset('cart_id');
>                  $table->unset('search_stores');
>                  $table->unset('page');
>                  # dont remove the source parameter. it is needed to decide
> on popup window
>                  #$table->unset('source');
>          }
>  }
>
> The above code is in May Pole..can i use the same code in catalyst and get
> the result which we got previously.Just go through it thoroughly and help
> me,thank you.
>

It would probably be best to refactor your code in Catalyst style,
instead of trying to use your existing Maypole design.  That being
said, you can probably accomplish the html thing pretty much the way
Chisel said.  Perhaps make it a forward to the other methods,
something more like:

package testimonials;

sub path_magic : LocalRegex('^(.*).html$') {
  my ($self, $c) = @_;
  $c->forward($c->req->snippets->[0]);
}

sub list : Local {
   ...
}

Or you could just edit your templates and remove the ".html" part.

I never used Maypole, so most of your code makes very little sense to me.

-- Brandon



More information about the Catalyst mailing list