script/de_opm.pl untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 10 Podpod n/a totaltotal 0.0% 0 / 83 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 # PODNAME: de_opm.pl
4 # ABSTRACT: create the files listed in the .opm (unpack it)
5  
6 use strict;
7 use warnings;
8  
9 our $VERSION = '1.06'; # VERSION
10  
11 use LWP::Simple qw(getstore);
12 use File::Basename;
13 use File::Path qw(make_path);
14 use File::Spec;
15 use File::Temp;
16 use FindBin;
17 use Getopt::Long;
18  
19 use OPM::Parser;
20  
21 GetOptions(
22 'ignore-validation' => \my $ignore_validation,
23 );
24  
25 my $location = $ARGV[0];
26 my $out_dir = $ARGV[1];
27  
28 if ( $location =~ m{ \A (?:f|ht)tp:// } ) {
29 my ($fh,$file) = File::Temp::tempfile();
30 close $fh;
31
32 getstore( $location, $file );
33
34 $location = $file;
35 }
36  
37 if ( !-f $location ) {
38 die "Usage: $0 <location> <output_directory>";
39 }
40  
41 my $object = OPM::Parser->new(
42 opm_file => $location,
43 );
44  
45 $object->parse( ignore_validation => $ignore_validation )
46 or die $object->error_string;
47  
48 for my $file ( @{ $object->files } ) {
49 print "create $file->{filename}...\n";
50 my $full_path = File::Spec->catfile( $out_dir, $file->{filename} );
51 my $dir = dirname( $full_path );
52
53 make_path( $dir ) if !-e $dir;
54
55 open my $fh, '>', $full_path or next;
56 print $fh $file->{content};
57 close $fh;
58 }
59  
60 print "create ", $object->name, ".sopm...\n";
61 my $sopm_file = File::Spec->catfile(
62 $out_dir,
63 $object->name . '.sopm',
64 );
65  
66 open my $fh, '>', $sopm_file or exit 1;
67 print $fh $object->as_sopm;
68 close $fh;
69  
70 print "done\n";
71  
72 __END__