line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Insight::Scriptures; |
2
|
2
|
|
|
2
|
|
139291
|
use 5.006; use strict; use warnings; |
|
2
|
|
|
2
|
|
17
|
|
|
2
|
|
|
2
|
|
10
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
51
|
|
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
84
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
4
|
2
|
|
|
2
|
|
1029
|
use JSON::Lines; |
|
2
|
|
|
|
|
66522
|
|
|
2
|
|
|
|
|
20
|
|
5
|
2
|
|
|
2
|
|
74
|
use JSON; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
1
|
|
|
1
|
0
|
82
|
my ($pkg, $args) = @_; |
9
|
|
|
|
|
|
|
my $self = bless { |
10
|
|
|
|
|
|
|
scriptures => undef, |
11
|
|
|
|
|
|
|
scripture => undef, |
12
|
|
|
|
|
|
|
scripture_file => undef, |
13
|
|
|
|
|
|
|
index => -1, |
14
|
|
|
|
|
|
|
jsonl => JSON::Lines->new(), |
15
|
|
|
|
|
|
|
json => JSON->new->pretty(1)->canonical, |
16
|
|
|
|
|
|
|
directory => 'directory', |
17
|
1
|
50
|
|
|
|
8
|
%{ $args || {} }, |
|
1
|
|
|
|
|
50
|
|
18
|
|
|
|
|
|
|
}, $pkg; |
19
|
1
|
|
|
|
|
6
|
$self->{scriptures} = $self->directory($self->{directory}); |
20
|
1
|
50
|
|
|
|
5
|
$self->scripture($self->{scripture}) if ($self->{scripture}); |
21
|
1
|
|
|
|
|
4
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub architect { |
25
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
0
|
while (1) { |
28
|
0
|
|
|
|
|
0
|
print "insight: "; |
29
|
0
|
|
|
|
|
0
|
my $in = ; |
30
|
0
|
|
|
|
|
0
|
chomp($in); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
my %options = ( |
33
|
|
|
|
|
|
|
abolish => 1, |
34
|
|
|
|
|
|
|
current => 1, |
35
|
|
|
|
|
|
|
next => 1, |
36
|
|
|
|
|
|
|
previous => 1, |
37
|
|
|
|
|
|
|
start => 1, |
38
|
|
|
|
|
|
|
end => 1, |
39
|
|
|
|
|
|
|
salvage => 1, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
0
|
if ($in eq 'help') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
43
|
0
|
|
|
|
|
0
|
print qq| |
44
|
|
|
|
|
|
|
Welcome to Insight::Scriptures architect. This is a small module to assist in writing your own scriptures. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Help: |
47
|
|
|
|
|
|
|
scripture \$scripture - loads the file containing the scripture lines |
48
|
|
|
|
|
|
|
feather \$text - extends the scripture from the current index |
49
|
|
|
|
|
|
|
abolish - deletes the current index from the scripture |
50
|
|
|
|
|
|
|
current - print the line for the current index |
51
|
|
|
|
|
|
|
next - move to the next index of the scripture and print the line |
52
|
|
|
|
|
|
|
previous - move to the previous index of the scripture and print line |
53
|
|
|
|
|
|
|
salvage - saves the scripture |
54
|
|
|
|
|
|
|
exit - quits the command line application |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|; |
57
|
|
|
|
|
|
|
} elsif ($options{$in}) { |
58
|
0
|
0
|
|
|
|
0
|
if ($in eq 'salvage') { |
59
|
0
|
|
|
|
|
0
|
$self->$in(); |
60
|
0
|
|
|
|
|
0
|
print qq|Scripture salvaged\n|; |
61
|
|
|
|
|
|
|
} else { |
62
|
0
|
|
|
|
|
0
|
my $enc = $self->{json}->encode($self->$in()); |
63
|
0
|
|
|
|
|
0
|
print $self->{index} . ": " . $enc; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} elsif ($in =~ m/scripture (.*)/) { |
66
|
0
|
|
|
|
|
0
|
$self->scripture($1); |
67
|
0
|
|
|
|
|
0
|
print qq|Scripture $1 read into memory\n|; |
68
|
|
|
|
|
|
|
} elsif ($in =~ m/chapter (.*)/) { |
69
|
0
|
|
|
|
|
0
|
$self->feather( chapter => 'scripture', text => $1 ); |
70
|
0
|
|
|
|
|
0
|
print qq|Chapter added to the scripture\n|; |
71
|
|
|
|
|
|
|
} elsif ($in =~ m/feather (.*)/) { |
72
|
0
|
|
|
|
|
0
|
$self->feather( text => $1 ); |
73
|
0
|
|
|
|
|
0
|
print qq|Text added to the scripture\n|; |
74
|
|
|
|
|
|
|
} elsif ($in eq 'exit') { |
75
|
0
|
|
|
|
|
0
|
last; |
76
|
|
|
|
|
|
|
} else { |
77
|
0
|
|
|
|
|
0
|
print qq|Unknown options\n|; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub compose { |
83
|
0
|
|
|
0
|
0
|
0
|
my ($self, %args) = @_; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
0
|
if (! $self->{scripture} ) { |
86
|
0
|
|
|
|
|
0
|
die "Please select a scripture first before composing"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
0
|
my ($chapter, $verse) = (0, 0); |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
my $scripture = ""; |
92
|
0
|
|
|
|
|
0
|
for (@{ $self->{scripture} }) { |
|
0
|
|
|
|
|
0
|
|
93
|
0
|
0
|
|
|
|
0
|
if ($_->{chapter}) { |
94
|
0
|
|
|
|
|
0
|
$chapter++; |
95
|
0
|
|
|
|
|
0
|
$scripture .= sprintf "Chapter %s - %s\n", $chapter, $_->{text}; |
96
|
|
|
|
|
|
|
} else { |
97
|
0
|
|
|
|
|
0
|
$verse++; |
98
|
0
|
|
|
|
|
0
|
$scripture .= sprintf "%s:%s %s\n", $chapter, $verse, $_->{text}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
print $scripture; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub directory { |
106
|
1
|
|
|
1
|
0
|
3
|
my ($self, $path) = @_; |
107
|
|
|
|
|
|
|
|
108
|
1
|
50
|
|
|
|
20
|
mkdir $path if (! -d $path); |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
3
|
my (@scriptures); |
111
|
1
|
50
|
|
|
|
45
|
opendir my $dh, $path or die "Cannot open directory for reading: $!"; |
112
|
1
|
|
|
|
|
44
|
for (readdir $dh) { |
113
|
5
|
100
|
|
|
|
20
|
next if $_ =~ m/^\./; |
114
|
3
|
|
|
|
|
14
|
(my $scripture = $_) =~ s/\..*$//; |
115
|
3
|
|
|
|
|
12
|
push @scriptures, [$scripture, "$path/$_"] |
116
|
|
|
|
|
|
|
} |
117
|
1
|
|
|
|
|
16
|
closedir $dh; |
118
|
1
|
|
|
|
|
8
|
return \@scriptures; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub scriptures { |
122
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
123
|
0
|
|
|
|
|
0
|
my @scriptures; |
124
|
0
|
|
|
|
|
0
|
for (@{ $self->{scriptures} }) { |
|
0
|
|
|
|
|
0
|
|
125
|
0
|
|
|
|
|
0
|
push @scriptures, $_->[0]; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
0
|
return \@scriptures; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub scripture { |
131
|
1
|
|
|
1
|
0
|
9
|
my ($self, $name) = @_; |
132
|
1
|
|
|
|
|
2
|
my $scripture; |
133
|
1
|
|
|
|
|
2
|
for (@{ $self->{scriptures} }) { |
|
1
|
|
|
|
|
14
|
|
134
|
1
|
50
|
|
|
|
23
|
if ($_->[0] =~ m/^$name$/) { |
135
|
1
|
|
|
|
|
3
|
$scripture = $_; |
136
|
1
|
|
|
|
|
3
|
last; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
1
|
50
|
|
|
|
4
|
if (! $scripture ) { |
141
|
0
|
|
|
|
|
0
|
my $file = sprintf "%s/%s.lines", $self->{directory}, $name; |
142
|
0
|
0
|
|
|
|
0
|
open my $fh, '>', $file or die 'Cannot open file for writing'; |
143
|
0
|
|
|
|
|
0
|
print $fh ""; |
144
|
0
|
|
|
|
|
0
|
close $fh; |
145
|
0
|
|
|
|
|
0
|
$scripture = [ $name, $file ]; |
146
|
0
|
|
|
|
|
0
|
push @{ $self->{scriptures} }, $scripture; |
|
0
|
|
|
|
|
0
|
|
147
|
0
|
|
|
|
|
0
|
$self->{scripture} = []; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
1
|
|
|
|
|
3
|
$self->{scripture_file} = $scripture; |
151
|
|
|
|
|
|
|
|
152
|
1
|
|
|
|
|
5
|
$scripture = $self->{jsonl}->decode_file($scripture->[-1]); |
153
|
|
|
|
|
|
|
|
154
|
1
|
|
|
|
|
201
|
$self->{scripture} = $scripture; |
155
|
1
|
|
|
|
|
3
|
$self->{index} = -1; |
156
|
|
|
|
|
|
|
|
157
|
1
|
|
|
|
|
2
|
return $scripture; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub feather { |
161
|
2
|
|
|
2
|
0
|
8
|
my ($self, %args) = @_; |
162
|
|
|
|
|
|
|
|
163
|
2
|
|
|
|
|
5
|
$self->{index}++; |
164
|
|
|
|
|
|
|
|
165
|
2
|
50
|
|
|
|
7
|
if ($args{chapter}) { |
166
|
0
|
|
|
|
|
0
|
splice @{ $self->{scripture} }, $self->{index}, 0, \%args; |
|
0
|
|
|
|
|
0
|
|
167
|
0
|
|
|
|
|
0
|
return; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
2
|
|
|
|
|
8
|
my %line = ( |
171
|
|
|
|
|
|
|
time => time, |
172
|
|
|
|
|
|
|
%args, |
173
|
|
|
|
|
|
|
); |
174
|
|
|
|
|
|
|
|
175
|
2
|
|
|
|
|
4
|
splice @{ $self->{scripture} }, $self->{index}, 0, \%line; |
|
2
|
|
|
|
|
6
|
|
176
|
|
|
|
|
|
|
|
177
|
2
|
|
|
|
|
6
|
return \%line; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub salvage { |
181
|
1
|
|
|
1
|
0
|
3
|
my ($self) = @_; |
182
|
1
|
|
|
|
|
5
|
$self->{jsonl}->encode_file($self->{scripture_file}->[-1], $self->{scripture}); |
183
|
1
|
|
|
|
|
401
|
return $self; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub abolish { |
187
|
2
|
|
|
2
|
0
|
4
|
my ($self) = @_; |
188
|
2
|
|
|
|
|
3
|
splice @{ $self->{scripture} }, $self->{index}, 1; |
|
2
|
|
|
|
|
5
|
|
189
|
2
|
|
|
|
|
4
|
$self->{index}--; |
190
|
2
|
|
|
|
|
5
|
return $self->current(); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub current { |
194
|
2
|
|
|
2
|
0
|
13
|
my ($self) = @_; |
195
|
2
|
50
|
|
|
|
17
|
$self->{index} = 0 if ($self->{index} < 0); |
196
|
2
|
|
|
|
|
9
|
return $self->{scripture}->[$self->{index}]; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub next { |
200
|
1
|
|
|
1
|
0
|
5
|
my ($self) = @_; |
201
|
1
|
|
|
|
|
2
|
$self->{index}++; |
202
|
1
|
|
|
|
|
2
|
my $next = $self->{scripture}->[$self->{index}]; |
203
|
1
|
|
|
|
|
8
|
return $next; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub previous { |
207
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
208
|
0
|
|
|
|
|
|
$self->{index}--; |
209
|
0
|
|
|
|
|
|
return $self->{scripture}->[$self->{index}]; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub start { |
213
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
214
|
0
|
|
|
|
|
|
$self->{index} = 0; |
215
|
0
|
|
|
|
|
|
return $self->{scripture}->[$self->{index}]; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub end { |
219
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
220
|
0
|
|
|
|
|
|
$self->{index} = scalar @{ $self->{scripture} } - 1; |
|
0
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
return $self->{scripture}->[$self->{index}]; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
1; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
__END__ |