File Coverage

bin/spel-wizard.pl
Criterion Covered Total %
statement 52 61 85.2
branch 15 28 53.5
condition 3 9 33.3
subroutine 8 9 88.8
pod n/a
total 78 107 72.9


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2             # -*- cperl -*-
3             # PODNAME: spel-wizard.pl
4             # ABSTRACT: converts spelchunks to to plain text
5             #
6              
7              
8 38     38   217389 use strict;
  38         69  
  38         1616  
9              
10 38     38   28722 use Getopt::Long;
  38         646885  
  38         316  
11 38     38   30054 use Pod::Usage;
  38         3024424  
  38         5893  
12              
13 38     38   25360 use Config::Tiny;
  38         61253  
  38         1658  
14              
15 38     38   274 use File::Spec;
  38         70  
  38         1089  
16 38     38   22191 use File::ShareDir;
  38         1207694  
  38         2077  
17              
18 38     38   22895 use SpeL::Wizard;
  38         179  
  38         4885747  
19              
20             sub dieExit;
21              
22 38         9957911 my $version = 0.9;
23 38         171 my $author = 'Walter Daems ';
24              
25             ######################################
26             # Read command-line options/arguments
27             ####################################
28              
29 38         123 my $opt_help;
30             my $opt_man;
31 38         110 my $opt_showconfig = 0;
32 38         107 my $opt_verbose = 0;
33 38         85 my $opt_test = 0;
34 38         136 my $opt_debug;
35              
36              
37             my $result =
38             GetOptions( "help" => \$opt_help,
39             "man" => \$opt_man,
40             "showconfig" => \$opt_showconfig,
41 76     76   46415 "verbose" => sub{++$opt_verbose},
42 38   33     606 "test" => \$opt_test,
43             "debug=s" => \$opt_debug )
44             || pod2usage( -exitval => 1,
45             -output => \*STDERR );
46 38 50       6946 pod2usage( -exitval => 100, -verbose => 1 ) if ($opt_help);
47 38 50       138 pod2usage( -exitval => 101, -verbose => 2 ) if ($opt_man);
48              
49 38 50       201 my $argument = $ARGV[0] if( @ARGV == 1 );
50              
51 38 50 33     286 pod2usage( -message => "Incorrect number of arguments",
52             -exitval => 1,
53             -output => \*STDERR ) unless( $opt_showconfig
54             or
55             defined( $argument ) );
56              
57             ###################
58             # Read config file
59             #################
60             # use 1. specific location if SPELWIZARD_CONIG is set,
61             # 2. else, home configuration folder,
62             # 3. or else, distribution folder
63 38 50       330 my $home = $^O eq 'MSWin32' ? $ENV{'userprofile'} : $ENV{'HOME'};
64 38   33     1316 my $configdir = $ENV{'SPELWIZARD_CONFIG'}
65             // File::Spec->catfile( $home, '.spel-wizard' );
66 38         385 my $configfilename = ( File::Spec->catfile( $configdir, 'tts.conf' ) );
67 38 50       1368 $configfilename =
68             File::Spec->catfile( File::ShareDir::dist_dir( 'SpeL-Wizard' ) ,
69             "tts.conf") if ( ! -r $configfilename );
70 38 50       6875 dieExit( 13, "Error: cannot find config file" )
71             unless( -r $configfilename );
72 38 50       664 my $config = Config::Tiny->read( $configfilename )
73             or dieExit( 14, $Config::Tiny::errstr . "\nin file '$configfilename'\n" );
74              
75              
76             ########################
77             # generate opening line
78             ######################
79 38         17948 my $openingline = "spel-wizard.pl - v$version - $author";
80 38 50       1007 say STDERR $openingline . "\n" .
81             ("=" x length( $openingline ) )
82             if( $opt_verbose >= 1 );
83              
84 38         4876 say STDERR "- Reading configuration file from $configfilename";
85              
86 38 50       1450 if( $opt_showconfig ) {
87 0         0 say STDERR Data::Dumper->Dump( [ $config ], [ qw(Configuration) ] );
88 0         0 exit(0);
89             }
90              
91 38         566 my $spelWizard = SpeL::Wizard->new( $argument, $config );
92              
93             ###################
94             # do the hard work
95             #################
96              
97             # parse the aux file
98             eval {
99 38 100       220 $spelWizard->parseAuxFile( $opt_verbose, $opt_test )
100             or exit( 102 );
101 37         158 1;
102 38 50       118 } or do {
103 0         0 say STDERR "$@";
104 0         0 exit( 15 );
105             };
106              
107             # parse the spelidx file / generate the audio / generate the playlist
108             eval {
109 37         298 $spelWizard->parseChunks( $opt_verbose, $opt_test, $opt_debug );
110 37         254 1;
111 37 50       83 } or do {
112 0         0 say STDERR "$@";
113 0         0 exit( 16 );
114             };
115              
116             ########################
117             # generate closing line
118             ######################
119 37 50       484 say STDERR "Done." if( $opt_verbose >= 1 );
120              
121             #########################################################
122              
123             sub dieExit {
124 0     0     my ( $code, $message ) = @_;
125 0           say STDERR $message;
126 0           exit( $code );
127             }
128              
129             __END__