line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebAPI::DBIC::Resource::Role::Router; |
2
|
|
|
|
|
|
|
$WebAPI::DBIC::Resource::Role::Router::VERSION = '0.004001'; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
31088795
|
use Moo::Role; |
|
2
|
|
|
|
|
45487
|
|
|
2
|
|
|
|
|
21
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub uri_for { ## no critic (RequireArgUnpacking) |
9
|
0
|
|
|
0
|
1
|
|
my $self = shift; # %pk in @_ |
10
|
|
|
|
|
|
|
|
11
|
0
|
0
|
|
|
|
|
my $url = $self->router->uri_for(@_) |
12
|
|
|
|
|
|
|
or return; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
my $env = $self->request->env; |
15
|
0
|
|
|
|
|
|
my $prefix = $env->{SCRIPT_NAME}; |
16
|
0
|
0
|
|
|
|
|
return "$prefix/$url" unless wantarray; |
17
|
0
|
|
|
|
|
|
return ($prefix, $url); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub router { |
22
|
0
|
|
|
0
|
0
|
|
return shift->request->env->{'plack.router'}; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
1; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
__END__ |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=pod |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=encoding UTF-8 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 NAME |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
WebAPI::DBIC::Resource::Role::Router |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 VERSION |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
version 0.004001 |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This role provides methods to interface with the router. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
WebAPI::DBIC::Resource::Role::Router - interface with the router |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 METHODS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 uri_for |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$absolute_url = $self->uri_for( |
55
|
|
|
|
|
|
|
resource_class => $resource_class, # e.g. 'TestSchema::Result::Artist' |
56
|
|
|
|
|
|
|
1 => $artist_id # key value (first and only in this case) |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
($prefix_path, $relative_path) = $self->uri_for(...); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Uses the router to find a url that matches the given parameter hash. |
62
|
|
|
|
|
|
|
Returns undef if there's no match. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The Plack request env hash is used to get the router ('C<plack.router>') |
65
|
|
|
|
|
|
|
and the script url prefix ('C<SCRIPT_NAME>'). |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
When called in scalar context the absolute url is returned. This is the |
68
|
|
|
|
|
|
|
concatenation of the script url prefix and the relative path matched by the |
69
|
|
|
|
|
|
|
router. When called in list context the two values are returned separately. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 AUTHOR |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Tim Bunce <Tim.Bunce@pobox.com> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Tim Bunce. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
80
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |