| 1 | package Yukki::Web::Router; | ||
| 2 | 4 | $Yukki::Web::Router::VERSION = '0.991_002'; # TRIAL | |
| 3 | |||
| 4 | 4 | ▶ | $Yukki::Web::Router::VERSION = '0.991002';use v5.24; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 4 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 4 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 4 | extends 'Path::Router'; | |
| 9 | |||
| 10 | 4 | ▶ | use Yukki::Web::Router::Route; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 4 | ▶ | use Types::Standard qw( ArrayRef Str ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 4 | ▶ | use Type::Utils qw( class_type declare as where ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 4 | ▶ | use List::Util qw( all ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 4 | ▶ | use Yukki::Types qw( LoginName ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | |||
| 17 | 4 | ▶ | use namespace::clean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | |||
| 19 | # ABSTRACT: send requests to the correct controllers, yo | ||
| 20 | |||
| 21 | |||
| 22 | # Add support for slurpy variables, inline off because I haven't written the match | ||
| 23 | # generator function yet. | ||
| 24 | 4 | has '+route_class' => ( default => 'Yukki::Web::Router::Route' ); | |
| 25 | 4 | has '+inline' => ( default => 0 ); | |
| 26 | |||
| 27 | |||
| 28 | 4 | has app => ( | |
| 29 | is => 'ro', | ||
| 30 | isa => class_type('Yukki'), | ||
| 31 | required => 1, | ||
| 32 | weak_ref => 1, | ||
| 33 | handles => 'Yukki::Role::App', | ||
| 34 | ); | ||
| 35 | |||
| 36 | |||
| 37 | sub BUILD { | ||
| 38 | 0 | ▶ | my $self = shift; |
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 39 | |||
| 40 | $self->add_route('' => ( | ||
| 41 | defaults => { | ||
| 42 | redirect => 'page/view/main', | ||
| 43 | }, | ||
| 44 | acl => [ | ||
| 45 | 0 | ▶ | [ none => { action => sub { 1 } } ], |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 46 | ], | ||
| 47 | target => $self->controller('Redirect'), | ||
| 48 | )); | ||
| 49 | |||
| 50 | $self->add_route('login/?:action' => ( | ||
| 51 | defaults => { | ||
| 52 | action => 'page', | ||
| 53 | }, | ||
| 54 | validations => { | ||
| 55 | action => qr/^(?:page|submit|exit)$/, | ||
| 56 | }, | ||
| 57 | acl => [ | ||
| 58 | 0 | ▶ | [ none => { action => sub { 1 } } ], |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 59 | ], | ||
| 60 | target => $self->controller('Login'), | ||
| 61 | )); | ||
| 62 | |||
| 63 | $self->add_route('profile/?:action' => ( | ||
| 64 | defaults => { | ||
| 65 | action => 'profile', | ||
| 66 | }, | ||
| 67 | validations => { | ||
| 68 | action => qr/^(?:profile|update)$/, | ||
| 69 | }, | ||
| 70 | acl => [ | ||
| 71 | 0 | ▶ | [ none => { action => sub { 1 } } ], |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 72 | ], | ||
| 73 | target => $self->controller('Login'), | ||
| 74 | )); | ||
| 75 | |||
| 76 | 0 | $self->add_route('logout' => ( | |
| 77 | defaults => { | ||
| 78 | action => 'exit', | ||
| 79 | }, | ||
| 80 | acl => [ | ||
| 81 | [ none => { action => 'exit' } ] | ||
| 82 | ], | ||
| 83 | target => $self->controller('Login'), | ||
| 84 | )); | ||
| 85 | |||
| 86 | $self->add_route('page/:action/:repository/*:page' => ( | ||
| 87 | defaults => { | ||
| 88 | action => 'view', | ||
| 89 | repository => 'main', | ||
| 90 | }, | ||
| 91 | validations => { | ||
| 92 | action => qr/^(?:view|edit|history|diff|preview|attach|rename|remove)$/, | ||
| 93 | repository => qr/^[_a-z0-9]+$/i, | ||
| 94 | page => declare as ArrayRef[Str], where { | ||
| 95 | 0 | ▶ | all { /^[_a-z0-9-.]+(?:\.[_a-z0-9-]+)*$/i } @$_ |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 96 | }, | ||
| 97 | }, | ||
| 98 | 0 | acl => [ | |
| 99 | [ read => { action => [ qw( view preview history diff ) ] } ], | ||
| 100 | [ write => { action => [ qw( edit attach rename remove ) ] } ], | ||
| 101 | ], | ||
| 102 | target => $self->controller('Page'), | ||
| 103 | )); | ||
| 104 | |||
| 105 | $self->add_route('attachment/:action/:repository/+:file' => ( | ||
| 106 | defaults => { | ||
| 107 | action => 'download', | ||
| 108 | repository => 'main', | ||
| 109 | file => [ 'untitled.txt' ], | ||
| 110 | }, | ||
| 111 | validations => { | ||
| 112 | action => qr/^(?:view|upload|download|rename|remove)$/, | ||
| 113 | repository => qr/^[_a-z0-9]+$/i, | ||
| 114 | file => declare as ArrayRef[Str], where { | ||
| 115 | 0 | ▶ | all { /^[_a-z0-9-]+(?:\.[_a-z0-9-]+)*$/i } @$_ |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 116 | }, | ||
| 117 | }, | ||
| 118 | 0 | acl => [ | |
| 119 | [ read => { action => [ qw( view download ) ] } ], | ||
| 120 | [ write => { action => [ qw( upload rename remove ) ] } ], | ||
| 121 | ], | ||
| 122 | target => $self->controller('Attachment'), | ||
| 123 | )); | ||
| 124 | |||
| 125 | 0 | $self->add_route('admin/user/:action' => ( | |
| 126 | defaults => { | ||
| 127 | action => 'list', | ||
| 128 | special => 'admin_user', | ||
| 129 | }, | ||
| 130 | validations => { | ||
| 131 | action => qr/^(?:add|list)$/, | ||
| 132 | }, | ||
| 133 | acl => [ | ||
| 134 | [ read => { action => [ qw( list ) ] } ], | ||
| 135 | [ write => { action => [ qw( add ) ] } ], | ||
| 136 | ], | ||
| 137 | target => $self->controller('Admin::User'), | ||
| 138 | )); | ||
| 139 | |||
| 140 | 0 | $self->add_route('admin/user/:action/:login_name' => ( | |
| 141 | defaults => { | ||
| 142 | action => 'edit', | ||
| 143 | special => 'admin_user', | ||
| 144 | }, | ||
| 145 | validations => { | ||
| 146 | action => qr/^(?:edit|remove)$/, | ||
| 147 | login_name => LoginName, | ||
| 148 | }, | ||
| 149 | acl => [ | ||
| 150 | [ write => { action => [ qw( edit remove ) ] } ], | ||
| 151 | ], | ||
| 152 | target => $self->controller('Admin::User'), | ||
| 153 | )); | ||
| 154 | } | ||
| 155 | |||
| 156 | 4 | 1; | |
| 157 | |||
| 158 | __END__ | ||
| 159 | |||
| 160 | =pod | ||
| 161 | |||
| 162 | =encoding UTF-8 | ||
| 163 | |||
| 164 | =head1 NAME | ||
| 165 | |||
| 166 | Yukki::Web::Router - send requests to the correct controllers, yo | ||
| 167 | |||
| 168 | =head1 VERSION | ||
| 169 | |||
| 170 | version 0.991_002 | ||
| 171 | |||
| 172 | =head1 DESCRIPTION | ||
| 173 | |||
| 174 | This maps incoming paths to the controllers that should be used to handle them. | ||
| 175 | This is based on L<Path::Router>, but adds "slurpy" variables. | ||
| 176 | |||
| 177 | =head1 EXTENDS | ||
| 178 | |||
| 179 | L<Path::Router> | ||
| 180 | |||
| 181 | =head1 ATTRIBUTES | ||
| 182 | |||
| 183 | =head2 route_class | ||
| 184 | |||
| 185 | Defaults to L<Yukki::Web::Router::Route>. | ||
| 186 | |||
| 187 | =head2 inline | ||
| 188 | |||
| 189 | This is turned off because inline slurpy routing is not implemented. | ||
| 190 | |||
| 191 | =head2 app | ||
| 192 | |||
| 193 | This is the L<Yukki> handler. | ||
| 194 | |||
| 195 | =head1 METHODS | ||
| 196 | |||
| 197 | =head2 BUILD | ||
| 198 | |||
| 199 | Builds the routing table used by L<Yukki::Web>. | ||
| 200 | |||
| 201 | =head1 AUTHOR | ||
| 202 | |||
| 203 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||
| 204 | |||
| 205 | =head1 COPYRIGHT AND LICENSE | ||
| 206 | |||
| 207 | This software is copyright (c) 2017 by Qubling Software LLC. | ||
| 208 | |||
| 209 | This is free software; you can redistribute it and/or modify it under | ||
| 210 | the same terms as the Perl 5 programming language system itself. | ||
| 211 | |||
| 212 | =cut | ||