blib/lib/PMLTQ/Command/convert.pm

filter: Statementstmt 34.3% 22 / 64 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 3 totaltotal 28.5% 28 / 98 CC 14 SCAR 39.4
CC
14
Cov
26%
run
110.0
files_for_layer
12.0
load_filelist
12.0
CRAP 51.3
« blib/lib/PMLTQ/Relation/CurrentFilelistTreesIterator.pm ↑ Summary blib/lib/PMLTQ/Relation/DescendantIteratorWithBoundedDepth.pm »
1 package PMLTQ::Command::convert;
2 1 our $AUTHORITY = 'cpan:MATY';
3 1 $PMLTQ::Command::convert::VERSION = '1.2.2';
4 # ABSTRACT: Converts PML files to SQL
5  
6 1 ▶use PMLTQ::Base 'PMLTQ::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use File::Path qw( make_path );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Slurp 'read_file';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use PMLTQ::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use PMLTQ::PML2BASE;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Treex::PML;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶has usage => sub { shift->extract_usage };
Subroutine __ANON__: not called CC=1 SCAR=1.2
15  
16 sub run {
17 0 ▶ my $self = shift;
Subroutine run: not called CC=10 SCAR=47.0
Pod undocumented
18  
19 0 my $config = $self->config;
20 0 my $output_dir = $config->{output_dir};
21  
22 0 ▶ unless ( -d $output_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $output_dir) 0 0 0
23 0 ▶ make_path($output_dir) or die "Unable to create directory $output_dir\n";
Branch: 1 branch
BranchTrueFalseTotal
make_path($output_dir) or die "Unable to create directory $output_dir\n" 0 0 0
24 }
25  
26 0 Treex::PML::AddResourcePath( $config->{resources} );
27  
28 0 ▶ unless ( @{ $config->{layers} } > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$config->{"layers"};} > 0) 0 0 0
29 0 print STDERR 'Nothing to convert, no layers configured';
30 0 return;
31 }
32  
33 0 for my $layer ( @{ $config->{layers} } ) {
34 0 print STDERR "==== Converting data for layer $layer->{name}\n";
35  
36 0 $PMLTQ::PML2BASE::opts{'no-secondary-files'} = 1;
37 0 $PMLTQ::PML2BASE::opts{'resource-dir'} = $config->{resources};
38 0 ▶ $PMLTQ::PML2BASE::opts{'related-schema'} = $layer->{'related-schema'} || [];
Condition0%0/2
$layer->{'related-schema'} || []
l!l
00
MC/DC0%0/1
$layer->{'related-schema'} || []
$layer->{'related-schema'}
Truth table0%0/2
A
A= $layer->{'related-schema'}
Aresult
11
00
39 0 $PMLTQ::PML2BASE::opts{'data-dir'} = $config->{data_dir};
40 0 $PMLTQ::PML2BASE::opts{'output-dir'} = $output_dir;
41 0 %{ $PMLTQ::PML2BASE::opts{'ref'} } = ();
42 0 ▶ $PMLTQ::PML2BASE::opts{'ref'}{$_} = $layer->{'references'}{$_} for ( keys %{ $layer->{'references'} || {} } );
Branch: 1 branch
BranchTrueFalseTotal
$layer->{"references"} or {} 0 0 0
43 0 PMLTQ::PML2BASE::init();
44  
45 0 for my $file ( $self->files_for_layer($layer) ) {
46 0 print STDERR "$file\n";
47 0 my $fsfile = Treex::PML::Factory->createDocumentFromFile($file);
48 0 ▶ if ($Treex::PML::FSError) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Treex::PML::FSError) 0 0 0
49 0 die "Error loading file $file: $Treex::PML::FSError ($!)\n";
50 }
51 0 PMLTQ::PML2BASE::fs2base($fsfile);
52 }
53 0 PMLTQ::PML2BASE::finish();
54 0 PMLTQ::PML2BASE::destroy();
55 }
56 0 return 1;
57 }
58  
59 sub files_for_layer {
60 0 ▶ my ( $self, $layer ) = @_;
Subroutine files_for_layer: not called CC=3 SCAR=24.8
Pod undocumented
61  
62 0 ▶ if ( $layer->{data} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($layer->{'data'}) { } 0 0 0
elsif ($layer->{'filelist'}) { } 0 0 0
63 0 return glob( File::Spec->catfile( $self->config->{data_dir}, $layer->{data} ) );
64 } elsif ( $layer->{filelist} ) {
65 0 return $self->load_filelist( $layer->{filelist} );
66 }
67 }
68  
69 sub load_filelist {
70 0 ▶ my ( $self, $filelist ) = @_;
Subroutine load_filelist: not called CC=3 SCAR=24.8
Pod undocumented
71  
72 0 ▶ die "Filelist '$filelist' does not exists or is not readable!" unless -r $filelist;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $filelist 0 0 0
73  
74 0 ▶ map { File::Spec->file_name_is_absolute($_) ? $_ : File::Spec->catfile( $self->config->{data_dir}, $_ ) }
Branch: 1 branch
BranchTrueFalseTotal
'File::Spec'->file_name_is_absolute($_) ? : 0 0 0
75 0 grep { $_ !~ m/^\s*$/ } read_file( $filelist, chomp => 1, binmode => ':utf8' );
76 }
77  
78 1 1;
79  
80 __END__
« blib/lib/PMLTQ/Relation/CurrentFilelistTreesIterator.pm ↑ Summary blib/lib/PMLTQ/Relation/DescendantIteratorWithBoundedDepth.pm »