blib/lib/Yukki/Web/Router.pm

filter: Statementstmt 64.7% 33 / 51 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 52.9% 9 / 17 Podpod 100% 1 / 1 totaltotal 62.3% 43 / 69 CC 1 SCAR 3.9
CC
1
Cov
65%
BUILD
2.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.5
« blib/lib/Yukki/Web/Settings.pm ↑ Summary blib/lib/Yukki/User.pm »
1 package Yukki::Web::Router;
2 6 $Yukki::Web::Router::VERSION = '0.991_007'; # TRIAL
3 6 $Yukki::Web::Router::VERSION = '0.991007';
4 6 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 extends 'Path::Router';
9  
10 6 ▶use Yukki::Web::Router::Route;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 ▶use Types::Standard qw( ArrayRef Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Type::Utils qw( class_type declare as where );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use List::Util qw( all );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use Yukki::Types qw( LoginName );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 6 ▶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 6 has '+route_class' => ( default => 'Yukki::Web::Router::Route' );
25 6 has '+inline' => ( default => 0 );
26  
27  
28 6 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 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod documented
38 0 my $self = shift;
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 0 ▶ page => declare as ArrayRef[Str], where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 0 ▶ all { /^[_a-z0-9-.]+(?:\.[_a-z0-9-]+)*$/i } @$_
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 0 ▶ file => declare as ArrayRef[Str], where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
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 0 $self->add_route('admin/repository/:action' => (
156 defaults => {
157 action => 'list',
158 special => 'admin_repository',
159 },
160 validations => {
161 action => qr/^(?:add|list)$/,
162 },
163 acl => [
164 [ read => { action => [ qw( list ) ] } ],
165 [ write => { action => [ qw( add ) ] } ],
166 ],
167 target => $self->controller('Admin::Repository'),
168 ));
169  
170 0 $self->add_route('admin/repository/:action/:repository' => (
171 defaults => {
172 special => 'admin_repository',
173 },
174 validations => {
175 action => qr/^(?:initialize|remove|kill)$/,
176 },
177 acl => [
178 [ write => { action => [ qw( initialize remove kill ) ] } ],
179 ],
180 target => $self->controller('Admin::Repository'),
181 ));
182 }
183  
184 6 1;
185  
186 __END__
« blib/lib/Yukki/Web/Settings.pm ↑ Summary blib/lib/Yukki/User.pm »