summaryrefslogtreecommitdiffstats
path: root/lib/Jaos/WebApp/Dispatcher.pm
blob: 36ab0659fbfe920d741e7f3f08a430e19ca4c4f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package Jaos::WebApp::Dispatcher;
use strict;
use warnings;

sub new
{
  my $class   = shift;
  my $self    = {
    routes => [],
  };
  bless $self, $class;
}

sub connect
{
  my $self = shift;
  push @{$self->{routes}}, Jaos::WebApp::Route->new(@_); 
}

sub match
{
  my ($self, $app) = @_;
  for my $r (@{$self->{routes}}) {
    return $r if ($r->match($app));
  }
}


=head1 NAME

Jaos::WebApp::Dispatcher - Jaos::WebApp dispatcher

=head1 SYNOPSIS

 my $d = Jaos::WebApp::Dispatcher->new();
 $d->connect('/path', %options);
 my $route = $d->match($app, $request);

=head1 DESCRIPTION

This is the dispatcher for L<Jaos::WebApp> that maintains route connections to request paths and finds the appropriate route for the current request.

=head1 METHODS

=head2 new

Constructor.

=head2 connect

Connect the path to a L<Jaos::WebApp::Route>

=head2 match

Returns a L<Jaos::WebApp::Route> object (if available) for the current request.

=head1 AUTHOR

Jason Woodward <woodwardj@jaos.org>

=head1 LICENSE

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;