Outthentic/Glue/Perl.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 62 CC 3 SCAR 12.8
CC
3
Cov
0%
captures
6.0
story_variables
6.0
config
2.0
CRAP 3.6
1 package Outthentic::Glue::Perl;
2  
3 1;
4  
5 package main;
6  
7 use glue;
8 use strict;
9  
10 use JSON;
11  
12 our $VARIABLES;
13 our $CAPTURES;
14  
15 sub config {
16  
17 my $path = cache_dir()."/config.json";
18  
19 open CONF, $path or die "can't open file $path to read: $!";
20 my $data = join "", <CONF>;
21 close CONF;
22
23 my $json = JSON->new;
24 return $json->decode($data);
25  
26 }
27  
28  
29 sub captures {
30  
31 return $CAPTURES if $CAPTURES;
32  
33 my $path = cache_dir()."/captures.json";
34 open CAPT, $path or die "can't open file $path to read: $!";
35 my $data = join '', <CAPT>;
36 close CAPT;
37  
38 my $json = JSON->new;
39 $CAPTURES = $json->decode($data);
40  
41 return $CAPTURES;
42  
43 }
44  
45 sub capture {
46 captures()->[0]
47 }
48  
49 sub story_variables {
50  
51 return $VARIABLES if $VARIABLES;
52  
53 my $path = cache_dir()."/variables.json";
54 open VARS, $path or die "can't open file $path to read: $!";
55 my $data = join '', <VARS>;
56 close VARS;
57  
58 my $json = JSON->new;
59 $VARIABLES = $json->decode($data);
60  
61 return $VARIABLES;
62  
63 }
64  
65  
66 sub story_var {
67 story_variables()->{shift()}
68 }
69  
70 1;
71