line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wurm; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
13394
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
46
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
37
|
|
5
|
2
|
|
|
2
|
|
23
|
use v5.20; |
|
2
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
6
|
use Scalar::Util qw(); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
1291
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.0.8'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub import { |
12
|
2
|
|
|
2
|
|
8
|
my ($class, @symbols) = @_; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
|
|
3
|
my %symbols = map {$_ => 1} @symbols; |
|
1
|
|
|
|
|
4
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
50
|
|
|
|
7
|
require $class. '/mob.pm' if $symbols{mob}; |
17
|
2
|
100
|
|
|
|
916
|
require $class. '/let.pm' if $symbols{let}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub wrapp { |
21
|
1
|
|
|
1
|
1
|
22
|
my ($wurm, $mind) = @_; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
50
|
|
|
5
|
$wurm //= { }; |
24
|
1
|
|
33
|
|
|
8
|
$wurm->{mob} //= exists $INC{'Wurm/mob.pm'}; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
3
|
my $case = _ncase($wurm->{case}, $wurm->{mob}); |
27
|
1
|
|
|
|
|
3
|
my $pore = _upore($wurm->{pore}); |
28
|
|
|
|
|
|
|
my $app = sub { |
29
|
15
|
|
|
15
|
|
7156
|
my $env = shift; |
30
|
|
|
|
|
|
|
my $log = defined $env->{'psgix.logger'} |
31
|
|
|
|
|
|
|
? $env->{'psgix.logger'} |
32
|
|
|
|
|
|
|
: sub { } |
33
|
15
|
50
|
|
|
|
51
|
; |
34
|
|
|
|
|
|
|
my $meal = $case->({ |
35
|
|
|
|
|
|
|
env => $env, |
36
|
|
|
|
|
|
|
log => $log, |
37
|
|
|
|
|
|
|
tube => $env->{PATH_INFO}, |
38
|
15
|
|
|
|
|
65
|
mind => $mind, |
39
|
|
|
|
|
|
|
seen => '', |
40
|
|
|
|
|
|
|
grit => { }, |
41
|
|
|
|
|
|
|
vent => { }, |
42
|
|
|
|
|
|
|
view => undef, |
43
|
|
|
|
|
|
|
}); |
44
|
15
|
|
|
|
|
50
|
return $pore->(fold($meal, $wurm), $meal); |
45
|
1
|
|
|
|
|
4
|
}; |
46
|
|
|
|
|
|
|
|
47
|
1
|
50
|
|
|
|
4
|
return wantarray ? ($app, $wurm) : $app; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _ncase { |
51
|
1
|
|
|
1
|
|
2
|
my $wrap = shift; |
52
|
1
|
|
|
|
|
1
|
my $mob = shift; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return defined $wrap |
55
|
|
|
|
|
|
|
? sub { |
56
|
15
|
|
|
15
|
|
11
|
my $meal = shift; |
57
|
15
|
|
|
|
|
30
|
$meal->{tube} =~ s#\A/##; |
58
|
15
|
50
|
|
|
|
30
|
return $wrap->($mob ? Wurm::mob->new($meal) : $meal); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
: sub { |
61
|
0
|
|
|
0
|
|
0
|
my $meal = shift; |
62
|
0
|
|
|
|
|
0
|
$meal->{tube} =~ s#\A/##; |
63
|
0
|
0
|
|
|
|
0
|
return $mob ? Wurm::mob->new($meal) : $meal; |
64
|
|
|
|
|
|
|
} |
65
|
1
|
50
|
|
|
|
7
|
; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _upore { |
69
|
1
|
|
|
1
|
|
2
|
my $wrap = shift; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
return defined $wrap |
72
|
|
|
|
|
|
|
? sub { |
73
|
15
|
|
33
|
15
|
|
20
|
my $cast = $wrap->(@_) // _404(); |
74
|
15
|
50
|
|
|
|
99
|
return Scalar::Util::blessed($cast) ? $cast->finalize : $cast; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
: sub { |
77
|
0
|
|
0
|
0
|
|
0
|
my $cast = shift // _404(); |
78
|
0
|
0
|
|
|
|
0
|
return Scalar::Util::blessed($cast) ? $cast->finalize : $cast; |
79
|
|
|
|
|
|
|
} |
80
|
1
|
50
|
|
|
|
4
|
; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Guild and its navigators, who the spice has mutated over 4,000 years, |
84
|
|
|
|
|
|
|
# use the orange spice gas, which gives them the ability to fold space. |
85
|
|
|
|
|
|
|
# We, however, are just folding tubes. |
86
|
|
|
|
|
|
|
sub fold { |
87
|
27
|
|
|
27
|
1
|
21
|
my ($meal, $wurm) = @_; |
88
|
|
|
|
|
|
|
|
89
|
27
|
50
|
|
|
|
41
|
die "unable to fold (imaginary wurm)\n" unless defined $wurm; |
90
|
27
|
50
|
|
|
|
42
|
die "unable to fold (mangled wurm)\n" unless 'HASH' eq ref $wurm; |
91
|
|
|
|
|
|
|
|
92
|
27
|
50
|
|
|
|
41
|
if(defined $wurm->{gate}) { |
93
|
27
|
|
|
|
|
32
|
my $res = $wurm->{gate}->($meal); |
94
|
27
|
50
|
|
|
|
73
|
return $res |
95
|
|
|
|
|
|
|
if defined $res; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
27
|
100
|
50
|
|
|
52
|
if(($meal->{tube} // '') ne '') { |
99
|
18
|
|
|
|
|
16
|
my $atom = bend($meal); |
100
|
18
|
50
|
|
|
|
29
|
return _404() |
101
|
|
|
|
|
|
|
unless defined $atom; |
102
|
|
|
|
|
|
|
|
103
|
18
|
|
|
|
|
16
|
my $tube = $wurm->{tube}{$atom}; |
104
|
18
|
100
|
|
|
|
27
|
return _404() |
105
|
|
|
|
|
|
|
unless defined $tube; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# malkovich? |
108
|
12
|
|
|
|
|
16
|
my $res = fold($meal, $tube); |
109
|
12
|
50
|
|
|
|
30
|
return $res |
110
|
|
|
|
|
|
|
if defined $res; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
9
|
50
|
|
|
|
12
|
if(defined $wurm->{neck}) { |
114
|
9
|
|
|
|
|
12
|
my $res = $wurm->{neck}->($meal); |
115
|
9
|
100
|
|
|
|
27
|
return $res |
116
|
|
|
|
|
|
|
if defined $res; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
6
|
100
|
|
|
|
8
|
if(defined $wurm->{body}) { |
120
|
3
|
|
|
|
|
17
|
my $method = lc $meal->{env}{REQUEST_METHOD}; |
121
|
3
|
|
|
|
|
4
|
my $body = $wurm->{body}{$method}; |
122
|
3
|
100
|
|
|
|
4
|
if(defined $body) { |
123
|
1
|
|
|
|
|
3
|
my $res = $body->($meal); |
124
|
1
|
50
|
|
|
|
5
|
return $res |
125
|
|
|
|
|
|
|
if defined $res; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
6
|
100
|
|
|
|
10
|
if(defined $wurm->{tail}) { |
130
|
3
|
|
|
|
|
4
|
my $res = $wurm->{tail}->($meal); |
131
|
3
|
100
|
|
|
|
11
|
return $res |
132
|
|
|
|
|
|
|
if defined $res; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
4
|
|
|
|
|
6
|
return _404(); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# There is no spoon. There are a series of tubes. Bendy ones. |
139
|
|
|
|
|
|
|
sub bend { |
140
|
18
|
|
|
18
|
1
|
13
|
my ($meal) = @_; |
141
|
|
|
|
|
|
|
|
142
|
18
|
50
|
|
|
|
64
|
$meal->{tube} =~ s#\A(?[^/]+)(?:/|\z)## |
143
|
|
|
|
|
|
|
or return; |
144
|
2
|
|
|
2
|
|
804
|
$meal->{seen} .= "$+{atom}/"; |
|
2
|
|
|
|
|
751
|
|
|
2
|
|
|
|
|
293
|
|
|
18
|
|
|
|
|
67
|
|
145
|
18
|
|
|
|
|
51
|
return $+{atom}; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# Happy, happy. Joy, joy. |
149
|
5
|
|
|
5
|
|
32
|
sub _200 {[200, ['Content-Type' => $_[0]], [$_[1]]]} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# |
152
|
0
|
|
|
0
|
|
0
|
sub _201 {[201, ['Location' => $_[0]], []]} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# There can be only none! |
155
|
0
|
|
|
0
|
|
0
|
sub _204 {[204, [], []]} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# One pluseth two verily to thus be thine six hundreds and three, sir. |
158
|
0
|
|
|
0
|
|
0
|
sub _301 {[301, ['Location' => $_[0]], []]} |
159
|
1
|
|
|
1
|
|
8
|
sub _302 {[302, ['Location' => $_[0]], []]} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# Down in a hole. Losing my soul. |
162
|
1
|
|
|
1
|
|
6
|
sub _400 {[400, ['Content-Type', 'text/plain'], ['.oOo.']]} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# Istanbul is Constantinople. |
165
|
18
|
|
|
18
|
|
66
|
sub _404 {[404, ['Content-Type' => 'text/plain'], ['Not Found']]} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# My eyes. The goggles do nothing. |
168
|
0
|
|
|
0
|
|
|
sub _500 {[500, ['Content-Type' => 'text/plain'], ['Internal Server Error']]} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
'.oOo.' # in wurm i trust |
171
|
|
|
|
|
|
|
__END__ |