| 1 | package Yukki::Web::Router; | ||
| 2 | { | ||
| 3 | $Yukki::Web::Router::VERSION = '0.140290'; | ||
| 4 | } | ||
| 5 | use Moose; | ||
| 6 | |||
| 7 | extends 'Path::Router'; | ||
| 8 | |||
| 9 | use Yukki::Web::Router::Route; | ||
| 10 | |||
| 11 | use Moose::Util::TypeConstraints qw( subtype where ); | ||
| 12 | use List::MoreUtils qw( all ); | ||
| 13 | |||
| 14 | # ABSTRACT: send requests to the correct controllers, yo | ||
| 15 | |||
| 16 | |||
| 17 | # Add support for slurpy variables, inline off because I haven't written the match | ||
| 18 | # generator function yet. | ||
| 19 | has '+route_class' => ( default => 'Yukki::Web::Router::Route' ); | ||
| 20 | has '+inline' => ( default => 0 ); | ||
| 21 | |||
| 22 | |||
| 23 | has app => ( | ||
| 24 | is => 'ro', | ||
| 25 | isa => 'Yukki', | ||
| 26 | required => 1, | ||
| 27 | weak_ref => 1, | ||
| 28 | handles => 'Yukki::Role::App', | ||
| 29 | ); | ||
| 30 | |||
| 31 | |||
| 32 | sub BUILD { | ||
| 33 | my $self = shift; | ||
| 34 | |||
| 35 | $self->add_route('' => ( | ||
| 36 | defaults => { | ||
| 37 | redirect => 'page/view/main', | ||
| 38 | }, | ||
| 39 | acl => [ | ||
| 40 | [ none => { action => sub { 1 } } ], | ||
| 41 | ], | ||
| 42 | target => $self->controller('Redirect'), | ||
| 43 | )); | ||
| 44 | |||
| 45 | $self->add_route('login/?:action' => ( | ||
| 46 | defaults => { | ||
| 47 | action => 'page', | ||
| 48 | }, | ||
| 49 | validations => { | ||
| 50 | action => qr/^(?:page|submit|exit)$/, | ||
| 51 | }, | ||
| 52 | acl => [ | ||
| 53 | [ none => { action => sub { 1 } } ], | ||
| 54 | ], | ||
| 55 | target => $self->controller('Login'), | ||
| 56 | )); | ||
| 57 | |||
| 58 | $self->add_route('logout' => ( | ||
| 59 | defaults => { | ||
| 60 | action => 'exit', | ||
| 61 | }, | ||
| 62 | acl => [ | ||
| 63 | [ none => { action => 'exit' } ] | ||
| 64 | ], | ||
| 65 | target => $self->controller('Login'), | ||
| 66 | )); | ||
| 67 | |||
| 68 | $self->add_route('page/:action/:repository/*:page' => ( | ||
| 69 | defaults => { | ||
| 70 | action => 'view', | ||
| 71 | repository => 'main', | ||
| 72 | }, | ||
| 73 | validations => { | ||
| 74 | action => qr/^(?:view|edit|history|diff|preview|attach|rename|remove)$/, | ||
| 75 | repository => qr/^[_a-z0-9]+$/i, | ||
| 76 | page => subtype('ArrayRef[Str]' => where { | ||
| 77 | all { /^[_a-z0-9-.]+(?:\.[_a-z0-9-]+)*$/i } @$_ | ||
| 78 | }), | ||
| 79 | }, | ||
| 80 | acl => [ | ||
| 81 | [ read => { action => [ qw( view preview history diff ) ] } ], | ||
| 82 | [ write => { action => [ qw( edit attach rename remove ) ] } ], | ||
| 83 | ], | ||
| 84 | target => $self->controller('Page'), | ||
| 85 | )); | ||
| 86 | |||
| 87 | $self->add_route('attachment/:action/:repository/+:file' => ( | ||
| 88 | defaults => { | ||
| 89 | action => 'download', | ||
| 90 | repository => 'main', | ||
| 91 | file => [ 'untitled.txt' ], | ||
| 92 | }, | ||
| 93 | validations => { | ||
| 94 | action => qr/^(?:view|upload|download|rename|remove)$/, | ||
| 95 | repository => qr/^[_a-z0-9]+$/i, | ||
| 96 | file => subtype('ArrayRef[Str]' => where { | ||
| 97 | all { /^[_a-z0-9-]+(?:\.[_a-z0-9-]+)*$/i } @$_ | ||
| 98 | }), | ||
| 99 | }, | ||
| 100 | acl => [ | ||
| 101 | [ read => { action => [ qw( view download ) ] } ], | ||
| 102 | [ write => { action => [ qw( upload rename remove ) ] } ], | ||
| 103 | ], | ||
| 104 | target => $self->controller('Attachment'), | ||
| 105 | )); | ||
| 106 | } | ||
| 107 | |||
| 108 | 1; | ||
| 109 | |||
| 110 | __END__ |