| 1 | package Labyrinth::Paths; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 6 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 9 | # Library Modules | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use IO::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Labyrinth; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Labyrinth::Variables; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 3 | my ($class,$pathfile) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # create an attributes hash | ||||||||||||||||||||||||||||
| 45 | my $atts = { | ||||||||||||||||||||||||||||
| 46 | 3 | ▶ | pathfile => $pathfile || $settings{pathfile} || './pathfile.json' | ||||||||||||||||||||||||||
|
Condition100%5/5
$pathfile || $Labyrinth::Paths::settings{'pathfile'} || './pathfile.json'
$pathfile or $Labyrinth::Paths::settings{"pathfile"}
MC/DC100%2/2
$pathfile || $Labyrinth::Paths::settings{'pathfile'} || './pathfile.json'
$pathfile
$Labyrinth::Paths::settings{"pathfile"}
Truth table100%3/3
A or B
A= $pathfileB= $Labyrinth::Paths::settings{"pathfile"}
| |||||||||||||||||||||||||||||
| 47 | }; | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # create the object | ||||||||||||||||||||||||||||
| 50 | 3 | bless $atts, $class; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 3 | $atts->load; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 3 | 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 | 7 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 77 | 7 | my $file = shift; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 7 | ▶ | if($file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 1 | ▶ | return unless(-f $file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 1 | $self->{pathfile} = $file; | |||||||||||||||||||||||||||
| 82 | } else { | ||||||||||||||||||||||||||||
| 83 | 6 | ▶ | return unless(-f $self->{pathfile}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 5 | ▶ | my $fh = IO::File->new($self->{pathfile},'r') or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 5 | local $/ = undef; | |||||||||||||||||||||||||||
| 88 | 5 | my $json = <$fh>; | |||||||||||||||||||||||||||
| 89 | 5 | $fh->close; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 5 | eval { | |||||||||||||||||||||||||||
| 92 | 5 | my $data = decode_json($json); | |||||||||||||||||||||||||||
| 93 | 5 | $self->{data} = $data->{paths}; | |||||||||||||||||||||||||||
| 94 | }; | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 5 | return; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 6 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 6 | ▶ | my $path = $ENV{SCRIPT_URL} || $ENV{SCRIPT_NAME}; | ||||||||||||||||||||||||||
|
Condition100%3/3
$ENV{'SCRIPT_URL'} || $ENV{'SCRIPT_NAME'}
MC/DC100%2/2
$ENV{'SCRIPT_URL'} || $ENV{'SCRIPT_NAME'}
$ENV{'SCRIPT_URL'}
$ENV{'SCRIPT_NAME'}
Truth table100%3/3
A || B
A= $ENV{'SCRIPT_URL'}B= $ENV{'SCRIPT_NAME'}
| |||||||||||||||||||||||||||||
| 103 | 6 | ▶ | return unless($path); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | for my $data (@{$self->{data}}) { | |||||||||||||||||||||||||||
| 106 | 3 | ▶ | if($path =~ /$data->{path}/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 2 | my @vars1 = ($1,$2,$3,$4,$5,$6,$7,$8,$9); | |||||||||||||||||||||||||||
| 108 | 2 | my @vars2 = @{$data->{variables}}; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 2 | ▶ | while(@vars1 && @vars2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@vars1 and @vars2
MC/DC50%1/2
@vars1 and @vars2
@vars1
@vars2
Truth table66%2/3
A and B
A= @vars1B= @vars2
| |||||||||||||||||||||||||||||
| 111 | 2 | my $name = shift @vars2; | |||||||||||||||||||||||||||
| 112 | 2 | $cgiparams{$name} = shift @vars1; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 2 | $cgiparams{$_} = $data->{cgiparams}{$_} for(keys %{$data->{cgiparams}}); | |||||||||||||||||||||||||||
| 116 | 2 | $settings{$_} = $data->{settings}{$_} for(keys %{$data->{settings}}); | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 2 | return; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 6 | 1; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||