Re: [Catalyst] Regex -- optional index.html

2007-03-02 Thread Bill Moseley
On Thu, Mar 01, 2007 at 04:13:05PM -0800, Bill Moseley wrote:
 Seems that Catalyst first tries to match the full path, then tries to
 match a reduced path.  Adding a bit of debugging to Regex.pm's match()
 method:
 
 Request = /training/webcasts/webcast_data/162/foo.html
 
 Checking [training/webcasts/webcast_data/162/foo.html]
 Checking [training/webcasts/webcast_data/162]
 *MATCHED*

Ok, so is that a bug?  Or am I not understanding the docs?

# Regex

sub bar : Regex('^item(\d+)/order(\d+)$') { }

Matches any URL that matches the pattern in the action key, e.g.
http://localhost:3000/item23/order42. The '' around the regexp is
optional, but perltidy likes it. :)

So it seems that would also match:

http://localhost:3000/item23/order42/something.else

but the $ would indicate to me that it much only match the shorter
string.


-- 
Bill Moseley
[EMAIL PROTECTED]


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Regex -- optional index.html

2007-03-02 Thread Michael Reece

i don't think it's a bug.


Catalyst::Manual::Intro also says:

  You can pass variable arguments as part of the URL path, separated  
with forward slashes (/). If the action is a Regex or LocalRegex, the  
'$' anchor must be used. For example, suppose you want to handle /foo/ 
$bar/$baz, where $bar and $baz may vary:


sub foo : Regex('^foo$') { my ($self, $context, $bar, $baz) = @_; }
[..snip..]

  If a Regex or LocalRegex action doesn't use the '$' anchor, the  
action will still match a URL containing arguments, however the  
arguments won't be available via @_.



have you tried adding :Args(0) to the action?


On Mar 2, 2007, at 9:59 AM, Bill Moseley wrote:


On Thu, Mar 01, 2007 at 04:13:05PM -0800, Bill Moseley wrote:

Seems that Catalyst first tries to match the full path, then tries to
match a reduced path.  Adding a bit of debugging to Regex.pm's  
match()

method:

Request = /training/webcasts/webcast_data/162/foo.html

Checking [training/webcasts/webcast_data/162/foo.html]
Checking [training/webcasts/webcast_data/162]
*MATCHED*


Ok, so is that a bug?  Or am I not understanding the docs?

# Regex

sub bar : Regex('^item(\d+)/order(\d+)$') { }

Matches any URL that matches the pattern in the action key, e.g.
http://localhost:3000/item23/order42. The '' around the regexp is
optional, but perltidy likes it. :)

So it seems that would also match:

http://localhost:3000/item23/order42/something.else

but the $ would indicate to me that it much only match the shorter
string.


--
Bill Moseley
[EMAIL PROTECTED]


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/ 
catalyst@lists.rawmode.org/

Dev site: http://dev.catalyst.perl.org/


---
michael reece :: software engineer :: [EMAIL PROTECTED]



___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Regex -- optional index.html

2007-03-02 Thread Brian Kirkbride

Michael Reece wrote:

i don't think it's a bug.



snip


have you tried adding :Args(0) to the action?


That was my guess too, I've been bit by this problem before adding Args(0) to my 
actions.


- Brian

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Regex -- optional index.html

2007-03-01 Thread Boris Ćeranić

On 01/03/07, Bill Moseley [EMAIL PROTECTED] wrote:

I want to match these two (not using Chained, btw):

/training/webcasts/webcast_data/186/
/training/webcasts/webcast_data/186/index.html

But not this:

/training/webcasts/webcast_data/186/foo.html



(snip)




I tried these:


(snip)


Regex('^training/webcasts/webcast_data/(\d+)/?(index.html)?$')

matches:
../186/index.html   : yes
../186/foo.html : yes
../186/ : yes
../186  : yes



(snip)

Actually, this one works for me quite well - it should work fine for
following scenarios:

.../186
.../186/
.../186/index.html

In any other case, it will fail, as you can see:

$ perl -e 'print YES if webcast_data/186 =~
m|^webcast_data/(\d+)/?(index\.html)?$|;'
YES

$ perl -e 'print YES if webcast_data/186/ =~
m|^webcast_data/(\d+)/?(index\.html)?$|;'
YES

$ perl -e 'print YES if webcast_data/186/index.html =~
m|^webcast_data/(\d+)/?(index\.html)?$|;'
YES

$ perl -e 'print YES if webcast_data/186/asdf.html =~
m|^webcast_data/(\d+)/?(index\.html)?$|;'


Regards,
Boris

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Regex -- optional index.html

2007-03-01 Thread Jon
How about this:

m!^training/webcasts/webcast_data/(\d+)/(index.html|$)!


On Thu, 2007-03-01 at 14:51 -0800, Bill Moseley wrote:
 I want to match these two (not using Chained, btw):
 
 /training/webcasts/webcast_data/186/
 /training/webcasts/webcast_data/186/index.html
 
 But not this:
 
 /training/webcasts/webcast_data/186/foo.html
 
 $ perl -le 'print YES if training/webcasts/webcast_data/186/index.html  
 =~  m!^training/webcasts/webcast_data/(\d+)/(index.html)?$!'
 YES
 $ perl -le 'print YES if training/webcasts/webcast_data/186/  =~  
 m!^training/webcasts/webcast_data/(\d+)/(index.html)?$!'
 YES
 $ perl -le 'print YES if training/webcasts/webcast_data/186/foo.html  =~  
 m!^training/webcasts/webcast_data/(\d+)/(index.html)?$!
 
 
 I tried these:
 
 Regex('^training/webcasts/webcast_data/(\d+)/(index.html)?$')
 
 matches:
 ../186/index.html   : yes
 ../186/foo.html : no
 ../186/ : no
 ../186  : no
 
 
 Regex('^training/webcasts/webcast_data/(\d+)/?(index.html)?$')
 
 matches:
 ../186/index.html   : yes
 ../186/foo.html : yes
 ../186/ : yes
 ../186  : yes
 
 
 Regex('^training/webcasts/webcast_data/(\d+)(/?index.html)?$')
 
 matches:
 ../186/index.html   : yes
 ../186/foo.html : yes
 ../186/ : yes
 ../186  : yes
 
 
 
 


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Regex -- optional index.html

2007-03-01 Thread Bill Moseley
On Fri, Mar 02, 2007 at 12:08:42AM +0100, Boris ?erani? wrote:
 Regex('^training/webcasts/webcast_data/(\d+)/?(index.html)?$')
 
 matches:
 ../186/index.html   : yes
 ../186/foo.html : yes
 ../186/ : yes
 ../186  : yes
 
 
 (snip)
 
 Actually, this one works for me quite well - it should work fine for
 following scenarios:
 
 .../186
 .../186/
 .../186/index.html
 
 In any other case, it will fail, as you can see:

Yes, when tested in Perl it works that way, but in Catalyst in other
cases it still matches.  That's the problem.

Seems that Catalyst first tries to match the full path, then tries to
match a reduced path.  Adding a bit of debugging to Regex.pm's match()
method:

Request = /training/webcasts/webcast_data/162/foo.html

Checking [training/webcasts/webcast_data/162/foo.html]
Checking [training/webcasts/webcast_data/162]
*MATCHED*

So that's why it's matchine when I don't want it to match.


-- 
Bill Moseley
[EMAIL PROTECTED]


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/