« 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
| |||||||||||||||
| 23 | 0 | ▶ | make_path($output_dir) or die "Unable to create directory $output_dir\n"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | } | ||||||||||||||
| 25 | |||||||||||||||
| 26 | 0 | Treex::PML::AddResourcePath( $config->{resources} ); | |||||||||||||
| 27 | |||||||||||||||
| 28 | 0 | ▶ | unless ( @{ $config->{layers} } > 0 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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'} || []
MC/DC0%0/1
$layer->{'related-schema'} || []
$layer->{'related-schema'}
Truth table0%0/2
A
A= $layer->{'related-schema'}
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 73 | |||||||||||||||
| 74 | 0 | ▶ | map { File::Spec->file_name_is_absolute($_) ? $_ : File::Spec->catfile( $self->config->{data_dir}, $_ ) } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 75 | 0 | grep { $_ !~ m/^\s*$/ } read_file( $filelist, chomp => 1, binmode => ':utf8' ); | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 1 | 1; | |||||||||||||
| 79 | |||||||||||||||
| 80 | __END__ | ||||||||||||||