| 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 |