| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Labyrinth::Paths; |
|
2
|
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
91177
|
use warnings; |
|
|
6
|
|
|
|
|
12
|
|
|
|
6
|
|
|
|
|
224
|
|
|
4
|
6
|
|
|
6
|
|
28
|
use strict; |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
287
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ------------------------------------- |
|
9
|
|
|
|
|
|
|
# Library Modules |
|
10
|
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
2512
|
use IO::File; |
|
|
6
|
|
|
|
|
38603
|
|
|
|
6
|
|
|
|
|
647
|
|
|
12
|
6
|
|
|
6
|
|
3263
|
use JSON::XS; |
|
|
6
|
|
|
|
|
34107
|
|
|
|
6
|
|
|
|
|
431
|
|
|
13
|
6
|
|
|
6
|
|
4899
|
use Labyrinth; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Labyrinth::Variables; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# ------------------------------------- |
|
17
|
|
|
|
|
|
|
# The Subs |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Labyrinth::Paths - CGI path translation for Labyrinth |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Allow Labyrinth to translate CGI paths into internal settings and parameters. |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 Constructor |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over 4 |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item new() |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Create a new path object. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=back |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new { |
|
42
|
|
|
|
|
|
|
my ($class,$pathfile) = @_; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# create an attributes hash |
|
45
|
|
|
|
|
|
|
my $atts = { |
|
46
|
|
|
|
|
|
|
pathfile => $pathfile || $settings{pathfile} || './pathfile.json' |
|
47
|
|
|
|
|
|
|
}; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# create the object |
|
50
|
|
|
|
|
|
|
bless $atts, $class; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$atts->load; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return $atts; |
|
55
|
|
|
|
|
|
|
}; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 Methods |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head3 Handling Actions |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over 4 |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item load( [$file] ) |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Load the given path file, which can be the default, or specified as a parameter. |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item parse() |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Parse the current path and reset cgiparams and settings values as appropriate. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=back |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub load { |
|
76
|
|
|
|
|
|
|
my $self = shift; |
|
77
|
|
|
|
|
|
|
my $file = shift; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
if($file) { |
|
80
|
|
|
|
|
|
|
return unless(-f $file); |
|
81
|
|
|
|
|
|
|
$self->{pathfile} = $file; |
|
82
|
|
|
|
|
|
|
} else { |
|
83
|
|
|
|
|
|
|
return unless(-f $self->{pathfile}); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $fh = IO::File->new($self->{pathfile},'r') or return; |
|
87
|
|
|
|
|
|
|
local $/ = undef; |
|
88
|
|
|
|
|
|
|
my $json = <$fh>; |
|
89
|
|
|
|
|
|
|
$fh->close; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
eval { |
|
92
|
|
|
|
|
|
|
my $data = decode_json($json); |
|
93
|
|
|
|
|
|
|
$self->{data} = $data->{paths}; |
|
94
|
|
|
|
|
|
|
}; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
return; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub parse { |
|
100
|
|
|
|
|
|
|
my $self = shift; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $path = $ENV{SCRIPT_URL} || $ENV{SCRIPT_NAME}; |
|
103
|
|
|
|
|
|
|
return unless($path); |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
for my $data (@{$self->{data}}) { |
|
106
|
|
|
|
|
|
|
if($path =~ /$data->{path}/) { |
|
107
|
|
|
|
|
|
|
my @vars1 = ($1,$2,$3,$4,$5,$6,$7,$8,$9); |
|
108
|
|
|
|
|
|
|
my @vars2 = @{$data->{variables}}; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
while(@vars1 && @vars2) { |
|
111
|
|
|
|
|
|
|
my $name = shift @vars2; |
|
112
|
|
|
|
|
|
|
$cgiparams{$name} = shift @vars1; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$cgiparams{$_} = $data->{cgiparams}{$_} for(keys %{$data->{cgiparams}}); |
|
116
|
|
|
|
|
|
|
$settings{$_} = $data->{settings}{$_} for(keys %{$data->{settings}}); |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
return; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |