| 1 | package Limper::Sugar; | ||||||||||||||||||||
| 2 | 1 | $Limper::Sugar::VERSION = '0.001'; | |||||||||||||||||||
| 3 | 1 | ▶ | use base 'Limper'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use 5.10.0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | ▶ | use File::Spec; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use File::Basename(); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | package # newline because Dist::Zilla::Plugin::PkgVersion and PAUSE indexer | ||||||||||||||||||||
| 12 | Limper; | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | push @Limper::EXPORT, qw/ limper_version load captures dirname halt send_error uri_for redirect content_type path /; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | ▶ | sub limper_version { $Limper::VERSION } | ||||||||||||||||||
|
Subroutine
limper_version: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 0 | ▶ | sub load { require $_ for @_ } | ||||||||||||||||||
|
Subroutine
load: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | sub captures { {%+} } | ||||||||||||||||||
|
Subroutine
captures: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 0 | ▶ | sub dirname { File::Basename::dirname($_[0]) } | ||||||||||||||||||
|
Subroutine
dirname: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | # WARNING: this does not exit the current route | ||||||||||||||||||||
| 25 | 0 | ▶ | sub halt { @_ } | ||||||||||||||||||
|
Subroutine
halt: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | # WARNING: this does not exit the current route | ||||||||||||||||||||
| 28 | sub send_error { | ||||||||||||||||||||
| 29 | 0 | ▶ | my ($content, $status) = @_; | ||||||||||||||||||
|
Subroutine
send_error: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 30 | 0 | ▶ | status $status // 500; | ||||||||||||||||||
|
Condition0%0/2
$status // 500
MC/DC0%0/1
$status // 500
$status
Truth table0%0/2
A
A= $status
| |||||||||||||||||||||
| 31 | 0 | $content; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 1 | my $scheme_rx = qr{^[a-z][a-z0-9+.-]*://}i; # RFC 2396 | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | sub uri_for { | ||||||||||||||||||||
| 37 | 0 | ▶ | return $_[0] unless $_[0] =~ $scheme_rx; | ||||||||||||||||||
|
Subroutine
uri_for: not called CC=3 SCAR=24.8
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 0 | ▶ | headers->{'x-forwarded-host'} // headers->{host}, $_[0]; | ||||||||||||||||||
|
Condition0%0/3
headers()->{"x-forwarded-host"} // headers()->{"host"}
MC/DC0%0/2
headers()->{"x-forwarded-host"} // headers()->{"host"}
headers()->{"x-forwarded-host"}
headers()->{"host"}
Truth table0%0/3
A // B
A= headers()->{"x-forwarded-host"}B= headers()->{"host"}
| |||||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | sub redirect { | ||||||||||||||||||||
| 42 | 0 | ▶ | my ($uri, $status) = @_; | ||||||||||||||||||
|
Subroutine
redirect: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 43 | 0 | ▶ | status $status // 302; | ||||||||||||||||||
|
Condition0%0/2
$status // 302
MC/DC0%0/1
$status // 302
$status
Truth table0%0/2
A
A= $status
| |||||||||||||||||||||
| 44 | 0 | headers headers, Location => uri_for $uri; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | sub content_type { | ||||||||||||||||||||
| 48 | 0 | ▶ | headers headers, 'Content-Type' => $_[0]; | ||||||||||||||||||
|
Subroutine
content_type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | sub path { | ||||||||||||||||||||
| 52 | 0 | ▶ | $_ = File::Spec->catfile(@_); | ||||||||||||||||||
|
Subroutine
path: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 53 | 0 | s|/\./|/|g; | |||||||||||||||||||
| 54 | 0 | ▶ | 1 while s|[^/]*/\.\./||g; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 0 | $_; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 1 | 1; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =for Pod::Coverage | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =head1 NAME | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | Limper::Sugar - sugary things like Dancer does | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =head1 VERSION | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | version 0.001 | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =head1 SYNOPSIS | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | use Limper::Sugar; | ||||||||||||||||||||
| 73 | use Limper; # this must come after all extensions | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | # routes | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | limp; | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =head1 DESCRIPTION | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | B<Limper::Sugar> extends L<Limper> to have sugary things like in L<Dancer>. | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | B<NOTE>: this is all as yet untested. | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | B<USE OF THIS MODULE IS STRONGLY DISCOURAGED IN PUBLIC CODE. DO NOT USE IT | ||||||||||||||||||||
| 86 | IN A PLUGIN.> It is meant to facilitate switching from Dancer. Consider | ||||||||||||||||||||
| 87 | everything in here B<deprecated>. Some of these may end up in Limper proper | ||||||||||||||||||||
| 88 | at some point, while others offer no significant benefit. If you really | ||||||||||||||||||||
| 89 | feel it should be in L<Limper>, make a request. | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =head1 EXPORTS | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | The following are all additionally exported by default: | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | limper_version load captures dirname halt send_error uri_for redirect content_type path | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =head1 FUNCTIONS | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =head2 limper_version | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | Returns the version of Limper in use. | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | =head2 load | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | Sugar around Perl's B<require>, but can take a list of expressions to require. | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =head2 captures | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | Returns a copy of C<%+> (named capture groups) as a hashref. | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | =head2 dirname | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | Exactly the same as L<File::Basename/dirname>. | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =head2 uri_for | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | Prepends C<< headers->{'x-forwarded-host'} // headers->{host} >> to path. | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | using the request's X-Forwarded-Host or Host value: | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =head2 redirect | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | redirect $path, $status; | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | Sugar for the following, plus it will turn a Limper path into a URI. | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | status $status // 302; | ||||||||||||||||||||
| 128 | headers headers, Location => uri_for $path; | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | =head2 content_type | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | Sugar for C<< headers headers 'Content-Type' => $type >>. | ||||||||||||||||||||
| 133 | Note that this does not support abbreviated content types. | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | =head2 path | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | Sugar around L<File::Spec/catfile>. | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | =head2 halt | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | Merely returns B<@_>. | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | B<Warning>: In Dancer, this stops execution of the route. In Limper, there | ||||||||||||||||||||
| 144 | is currently no such mechanism. This may change in the future. | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | =head2 send_error | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | send_error $content, $status; | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | Sugar for the following: | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | status $status // 500; | ||||||||||||||||||||
| 153 | $content; | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | B<Warning>: In Dancer, this stops execution of the route. In Limper, there | ||||||||||||||||||||
| 156 | is currently no such mechanism. This may change in the future. | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | Copyright (C) 2014 by Ashley Willis E<lt>ashley+perl@gitable.orgE<gt> | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 163 | it under the same terms as Perl itself, either Perl version 5.12.4 or, | ||||||||||||||||||||
| 164 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =head1 SEE ALSO | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | L<Limper> | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | =cut | ||||||||||||||||||||