Line # Revision Author
1 3 ahitrov@rambler.ru package Contenido::MVC::DispatchType::Path;
2
3 use strict;
4 use base 'Contenido::MVC::DispatchType';
5 use URI;
6 use Data::Dumper;
7
8 sub match {
9 my $self = shift;
10 my $path = shift || '/';
11
12 if (exists $self->{paths}->{$path}) {
13 return {
14 'sub' => $self->{paths}->{$path}->{'sub'},
15 'path' => $path,
16 'controller_class' => $self->{paths}->{$path}->{'controller_class'},
17 'snippets' => [],
18 (exists $self->{paths}->{$path}->{'begin'} ? ('begin' => $self->{paths}->{$path}->{'begin'}) : ()),
19 (exists $self->{paths}->{$path}->{'end'} ? ('end' => $self->{paths}->{$path}->{'end'}) : ()),
20 };
21 }
22
23 return undef;
24 }
25
26 sub register {
27 my $self = shift;
28 my $action = shift;
29
30 return undef unless $action && ref($action) eq 'HASH';
31
32 my $path = $action->{'path'};
33 $path = '/' unless length $path;
34 $path = URI->new($path)->canonical();
35
36 $self->{paths}->{$path} = {
37 'sub' => $action->{'sub'},
38 'controller_class' => $action->{'controller_class'},
39 (exists $action->{'begin'} ? ('begin' => $action->{'begin'}) : ()),
40 (exists $action->{'end'} ? ('end' => $action->{'end'}) : ()),
41 };
42
43 return 1;
44 }
45
46 1;