blib/lib/ECHR/OpenData.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 56 CC 2 SCAR 11.0
CC
2
Cov
0%
test_print
6.0
extract_hashref_from_file
2.0
BEGIN
2.0
CRAP 3.0
1 package ECHR::OpenData;
2 use strict;
3 use warnings;
4 our $VERSION = '0.01';
5
6 use JSON;
7 use Data::Dumper;
8 use File::Spec;
9
10 =pod
11 USAGE:
12
13 my $whole_data_subfolder = "C:/pl/testing_cpan/echr_dl/echr_2_0_0/build/echr_database/raw/preprocessed_documents";
14 my $fn = "001-86725_parsed.json";
15 ECHR::OpenData::test_print($whole_data_subfolder, $fn);
16
17 =cut
18
19 $| = 1;
20
21 sub extract_hashref_from_file{
22 my $dir = shift;
23 my $fn = shift;
24 my $full_file_path = File::Spec->catdir($dir, $fn);
25 open FH, "<$full_file_path" or die $!;
26 my $json_text = do {local $/; <FH>};
27 my $perl_scalar = decode_json( $json_text );
28 return $perl_scalar;
29 }
30
31 sub test_print{
32 my $whole_data_subfolder = shift;
33 printf "whole_data_subfolder = %s\n", $whole_data_subfolder;
34 opendir(D, "$whole_data_subfolder") || die "Can't open directory $whole_data_subfolder: $!\n";
35 my @file_list = readdir(D);
36 my @aoh;
37 my $count = 0;
38 foreach my $entry (@file_list) {
39 if($entry =~ /\.json$/){
40 $count++;
41 my $perl_scalar = extract_hashref_from_file($whole_data_subfolder, $entry);
42 printf "%6d %s\n", $count, $perl_scalar->{__conclusion};
43 }
44 }
45 closedir(D);
46 return @aoh;
47 }
48
49 1;