| 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.02'; | |||||||||||||||||||||||||||
| 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 FUNCTIONS | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head2 Constructor | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =over 4 | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =item new() | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | Create a new path object. | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =back | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub new { | ||||||||||||||||||||||||||||
| 34 | 3 | ▶ | my ($class,$pathfile) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # create an attributes hash | ||||||||||||||||||||||||||||
| 37 | my $atts = { | ||||||||||||||||||||||||||||
| 38 | 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"}
| |||||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # create the object | ||||||||||||||||||||||||||||
| 42 | 3 | bless $atts, $class; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 3 | $atts->load; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | return $atts; | |||||||||||||||||||||||||||
| 47 | }; | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head2 Methods | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head3 Handling Actions | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =over 4 | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =item load( [$file] ) | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Load the given path file, which can be the default, or specified as a parameter. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =item parse() | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Parse the current path and reset cgiparams and settings values as appropriate. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =back | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub load { | ||||||||||||||||||||||||||||
| 68 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 7 | my $file = shift; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 7 | ▶ | if($file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 1 | ▶ | return unless(-f $file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 1 | $self->{pathfile} = $file; | |||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||
| 75 | 6 | ▶ | return unless(-f $self->{pathfile}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 5 | ▶ | my $fh = IO::File->new($self->{pathfile},'r') or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 5 | local $/ = undef; | |||||||||||||||||||||||||||
| 80 | 5 | my $json = <$fh>; | |||||||||||||||||||||||||||
| 81 | 5 | $fh->close; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 5 | eval { | |||||||||||||||||||||||||||
| 84 | 5 | my $data = decode_json($json); | |||||||||||||||||||||||||||
| 85 | 5 | $self->{data} = $data->{paths}; | |||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 5 | return; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | sub parse { | ||||||||||||||||||||||||||||
| 92 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 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'}
| |||||||||||||||||||||||||||||
| 95 | 6 | ▶ | return unless($path); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 3 | for my $data (@{$self->{data}}) { | |||||||||||||||||||||||||||
| 98 | 3 | ▶ | if($path =~ /$data->{path}/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 2 | my @vars1 = ($1,$2,$3,$4,$5,$6,$7,$8,$9); | |||||||||||||||||||||||||||
| 100 | 2 | my @vars2 = @{$data->{variables}}; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 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
| |||||||||||||||||||||||||||||
| 103 | 2 | my $name = shift @vars2; | |||||||||||||||||||||||||||
| 104 | 2 | $cgiparams{$name} = shift @vars1; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 2 | $cgiparams{$_} = $data->{cgiparams}{$_} for(keys %{$data->{cgiparams}}); | |||||||||||||||||||||||||||
| 108 | 2 | $settings{$_} = $data->{settings}{$_} for(keys %{$data->{settings}}); | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 2 | return; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 6 | 1; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | L<Labyrinth> | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | Barbie, <barbie@missbarbell.co.uk> for | ||||||||||||||||||||||||||||
| 126 | Miss Barbell Productions, L<http://www.missbarbell.co.uk/> | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | Copyright (C) 2015 Barbie for Miss Barbell Productions | ||||||||||||||||||||||||||||
| 131 | All Rights Reserved. | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | This distribution is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||
| 134 | modify it under the Artistic License 2.0. | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||||||||||