« blib/lib/Video/DVDRip/Cluster/JobPlanner.pm
↑ Summary
blib/lib/Video/DVDRip/GUI/FormFactory/SubtitlePreviews.pm »
| 1 | # $Id: Base.pm 2280 2007-03-17 10:56:47Z joern $ | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 4 | # Copyright (C) 2001-2006 Jörn Reder <joern AT zyn.de>. | ||||||||||||||||||||||||||||||
| 5 | # All Rights Reserved. See file COPYRIGHT for details. | ||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||
| 7 | # This module is part of Video::DVDRip, which is free software; you can | ||||||||||||||||||||||||||||||
| 8 | # redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||
| 9 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | package Video::DVDRip::Base; | ||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Locale::TextDomain qw (video.dvdrip); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Video::DVDRip::Config; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Video::DVDRip::FilterList; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use FileHandle; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use IO::Pipe; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Fcntl; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||
| 24 | # load preferences --------------------------------------------------- | ||||||||||||||||||||||||||||||
| 25 | 1 | my $CONFIG_OBJECT = Video::DVDRip::Config->new; | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | $Video::DVDRip::PREFERENCE_FILE ||= "$ENV{HOME}/.dvdriprc"; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$Video::DVDRip::PREFERENCE_FILE ||= qq[$ENV{"HOME"}/.dvdriprc]
MC/DC0%0/1
$Video::DVDRip::PREFERENCE_FILE ||= qq[$ENV{"HOME"}/.dvdriprc]
$Video::DVDRip::PREFERENCE_FILE
Truth table50%1/2
A
A= $Video::DVDRip::PREFERENCE_FILE
| |||||||||||||||||||||||||||||||
| 27 | 1 | $CONFIG_OBJECT->set_filename($Video::DVDRip::PREFERENCE_FILE); | |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | $CONFIG_OBJECT->save if not -f $Video::DVDRip::PREFERENCE_FILE; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 29 | 1 | $CONFIG_OBJECT->load; | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||
| 31 | # detect installed tool versions ------------------------------------- | ||||||||||||||||||||||||||||||
| 32 | 1 | require Video::DVDRip::Depend; | |||||||||||||||||||||||||||||
| 33 | 1 | my $DEPEND_OBJECT = Video::DVDRip::Depend->new; | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | # pre load transcode's filter list ----------------------------------- | ||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | Video::DVDRip::FilterList->get_filter_list | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 37 | if $DEPEND_OBJECT->version("transcode") >= 603; | ||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||
| 39 | # init some config settings ------------------------------------------ | ||||||||||||||||||||||||||||||
| 40 | # (this depends on a loaded Config and Depend, that's why we call it here) | ||||||||||||||||||||||||||||||
| 41 | 1 | $CONFIG_OBJECT->init_settings; | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 44 | 0 | my $class = shift; | |||||||||||||||||||||||||||||
| 45 | 0 | return bless {}, $class; | |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||
| 48 | 2 | ▶ | sub config { | ||||||||||||||||||||||||||||
|
Subroutine
config: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 49 | 2 | my $thingy = shift; | |||||||||||||||||||||||||||||
| 50 | 2 | my ($name) = @_; | |||||||||||||||||||||||||||||
| 51 | 2 | return $CONFIG_OBJECT->get_value($name); | |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub set_config { | ||||||||||||||||||||||||||||
|
Subroutine
set_config: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 55 | 0 | my $thingy = shift; | |||||||||||||||||||||||||||||
| 56 | 0 | my ( $name, $value ) = @_; | |||||||||||||||||||||||||||||
| 57 | 0 | $CONFIG_OBJECT->set_value( $name, $value ); | |||||||||||||||||||||||||||||
| 58 | 0 | return $value; | |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub config_object { | ||||||||||||||||||||||||||||
|
Subroutine
config_object: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 62 | 0 | $CONFIG_OBJECT; | |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | sub depend_object { | ||||||||||||||||||||||||||||
|
Subroutine
depend_object: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 66 | 1 | $DEPEND_OBJECT; | |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | sub has { | ||||||||||||||||||||||||||||
|
Subroutine
has: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 70 | 1 | my $self = shift; | |||||||||||||||||||||||||||||
| 71 | 1 | my ($command) = @_; | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | 1 | return $self->depend_object->has($command); | |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub exists { | ||||||||||||||||||||||||||||
|
Subroutine
exists: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 78 | 0 | my ($command) = @_; | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||
| 80 | 0 | return $self->depend_object->exists($command); | |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub version { | ||||||||||||||||||||||||||||
|
Subroutine
version: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 84 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 85 | 0 | my ($command) = @_; | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | 0 | return $self->depend_object->version($command); | |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub debug_level { $Video::DVDRip::DEBUG || shift->{debug_level} } | ||||||||||||||||||||||||||||
|
Subroutine
debug_level: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub set_debug_level { | ||||||||||||||||||||||||||||
|
Subroutine
set_debug_level: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 93 | 0 | my $thing = shift; | |||||||||||||||||||||||||||||
| 94 | 0 | my $debug; | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ( ref $thing ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $thing->{debug_level} = shift if @_; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 97 | 0 | $debug = $thing->{debug_level}; | |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $Video::DVDRip::DEBUG = shift if @_; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 101 | 0 | $debug = $Video::DVDRip::DEBUG; | |||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($debug) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 105 | 0 | $Video::DVDRip::DEBUG::TIME = scalar( localtime(time) ); | |||||||||||||||||||||||||||||
| 106 | 0 | print STDERR "--- START ------------------------------------\n", | |||||||||||||||||||||||||||||
| 107 | "$$: $Video::DVDRip::DEBUG::TIME - DEBUG LEVEL $debug\n"; | ||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | 0 | return $debug; | |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub dump { | ||||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 114 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | push @_, $self if not @_; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||
| 117 | 0 | my $dd = Data::Dumper->new( \@_ ); | |||||||||||||||||||||||||||||
| 118 | 0 | $dd->Indent(1); | |||||||||||||||||||||||||||||
| 119 | 0 | print $dd->Dump; | |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||
| 121 | 0 | 1; | |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub print_debug { | ||||||||||||||||||||||||||||
|
Subroutine
print_debug: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 125 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||
| 127 | 0 | my $debug = $Video::DVDRip::DEBUG; | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | $debug = $self->{debug_level} if ref $self and $self->{debug_level}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $self and $self->{"debug_level"}
MC/DC0%0/2
ref $self and $self->{"debug_level"}
ref $self
$self->{"debug_level"}
Truth table0%0/3
A and B
A= ref $selfB= $self->{"debug_level"}
| |||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ($debug) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 131 | 0 | print STDERR join( "\n", @_ ), "\n"; | |||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||
| 134 | 0 | 1; | |||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub system { | ||||||||||||||||||||||||||||
|
Subroutine
system: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 138 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 139 | 0 | my %par = @_; | |||||||||||||||||||||||||||||
| 140 | my ( $command, $err_ignore, $return_rc ) | ||||||||||||||||||||||||||||||
| 141 | 0 | = @par{ 'command', 'err_ignore', 'return_rc' }; | |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||
| 143 | 0 | $self->log("Executing command: $command"); | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||
| 145 | 0 | $self->print_debug("executing command: $command"); | |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||
| 147 | 0 | my $catch = `($command) 2>&1`; | |||||||||||||||||||||||||||||
| 148 | 0 | my $rc = $?; | |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||
| 150 | 0 | $self->print_debug("got: rc=$rc catch=$catch"); | |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | croak "Error executing command $command:\n$catch" if $rc; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | return $return_rc ? $? : $catch; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub popen { | ||||||||||||||||||||||||||||
|
Subroutine
popen: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 158 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 159 | 0 | my %par = @_; | |||||||||||||||||||||||||||||
| 160 | 0 | my ( $command, $callback ) = @par{ 'command', 'callback' }; | |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | return $self->popen_with_callback(@_) if $callback; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||
| 164 | 0 | $self->print_debug("executing command: $command"); | |||||||||||||||||||||||||||||
| 165 | 0 | $self->log("Executing command: $command"); | |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||
| 167 | 0 | my $fh = FileHandle->new; | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | open( $fh, "($command) 2>&1 |" ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 169 | or croak "can't fork $command"; | ||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||
| 171 | 0 | my $flags = ''; | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | fcntl( $fh, F_GETFL, $flags ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 173 | or die "Can't get flags: $!\n"; | ||||||||||||||||||||||||||||||
| 174 | 0 | $flags |= O_NONBLOCK; | |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | fcntl( $fh, F_SETFL, $flags ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 176 | or die "Can't set flags: $!\n"; | ||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||
| 178 | 0 | return $fh; | |||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | sub popen_with_callback { | ||||||||||||||||||||||||||||
|
Subroutine
popen_with_callback: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 182 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 183 | 0 | my %par = @_; | |||||||||||||||||||||||||||||
| 184 | my ( $command, $callback, $catch_output ) | ||||||||||||||||||||||||||||||
| 185 | 0 | = @par{ 'command', 'callback', 'catch_output' }; | |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||
| 187 | 0 | $self->print_debug("executing command: $command"); | |||||||||||||||||||||||||||||
| 188 | 0 | $self->log("Executing command: $command"); | |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||
| 190 | 0 | my $fh = FileHandle->new; | |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | open( $fh, "($command) 2>&1 |" ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 192 | or croak "can't fork $command"; | ||||||||||||||||||||||||||||||
| 193 | 0 | select $fh; | |||||||||||||||||||||||||||||
| 194 | 0 | $| = 1; | |||||||||||||||||||||||||||||
| 195 | 0 | select STDOUT; | |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | return $fh if not $callback; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||
| 198 | 0 | my ( $output, $buffer ); | |||||||||||||||||||||||||||||
| 199 | 0 | ▶ | while ( read( $fh, $buffer, 512 ) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 200 | 0 | &$callback($buffer); | |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | $output .= $_ if $catch_output; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||
| 204 | 0 | close $fh; | |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||
| 206 | 0 | return $output; | |||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | sub format_time { | ||||||||||||||||||||||||||||
|
Subroutine
format_time: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 210 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 211 | 0 | my %par = @_; | |||||||||||||||||||||||||||||
| 212 | 0 | my ($time) = @par{'time'}; | |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||
| 214 | 0 | my ( $h, $m, $s ); | |||||||||||||||||||||||||||||
| 215 | 0 | $h = int( $time / 3600 ); | |||||||||||||||||||||||||||||
| 216 | 0 | $m = int( ( $time - $h * 3600 ) / 60 ); | |||||||||||||||||||||||||||||
| 217 | 0 | $s = $time % 60; | |||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||
| 219 | 0 | return sprintf( "%02d:%02d:%02d", $h, $m, $s ); | |||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | sub stripped_exception { | ||||||||||||||||||||||||||||
|
Subroutine
stripped_exception: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 223 | 0 | my $text = $@; | |||||||||||||||||||||||||||||
| 224 | 0 | $text =~ s/\s+at\s+[^\s]+\s+line\s+\d+\.?//; | |||||||||||||||||||||||||||||
| 225 | 0 | $text =~ s/^msg:\s*//; | |||||||||||||||||||||||||||||
| 226 | 0 | return $text; | |||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||
| 229 | 1 | my $logger; | |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | sub logger {$logger} | ||||||||||||||||||||||||||||
|
Subroutine
logger: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | sub set_logger { | ||||||||||||||||||||||||||||
|
Subroutine
set_logger: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 234 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 235 | 0 | my ($set_logger) = @_; | |||||||||||||||||||||||||||||
| 236 | 0 | return $logger = $set_logger; | |||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | sub log { | ||||||||||||||||||||||||||||
|
Subroutine
log: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 240 | 0 | shift; | |||||||||||||||||||||||||||||
| 241 | 0 | ▶ | return if not defined $logger; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 242 | 0 | $logger->log(@_); | |||||||||||||||||||||||||||||
| 243 | 0 | 1; | |||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub clone { | ||||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 247 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||
| 249 | 0 | require Storable; | |||||||||||||||||||||||||||||
| 250 | 0 | return Storable::dclone($self); | |||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | sub combine_command_options { | ||||||||||||||||||||||||||||
|
Subroutine
combine_command_options: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 254 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 255 | 0 | my %par = @_; | |||||||||||||||||||||||||||||
| 256 | 0 | my ( $cmd, $cmd_line, $options ) = @par{ 'cmd', 'cmd_line', 'options' }; | |||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||
| 258 | # split command line into separate commands | ||||||||||||||||||||||||||||||
| 259 | 0 | $cmd_line =~ s/\s+$//; | |||||||||||||||||||||||||||||
| 260 | 0 | ▶ | $cmd_line .= ";" if $cmd_line !~ /;$/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 261 | 0 | my @parts = grep !/^$/, | |||||||||||||||||||||||||||||
| 262 | ( $cmd_line | ||||||||||||||||||||||||||||||
| 263 | =~ m!(.*?)\s*(\(|\)|;|&&|\|\||\`which nice\`\s+-n\s+[\d-]+|execflow\s+(?:-n\s*\d+)?)\s*!g | ||||||||||||||||||||||||||||||
| 264 | ); | ||||||||||||||||||||||||||||||
| 265 | # walk through and process requested command | ||||||||||||||||||||||||||||||
| 266 | 0 | foreach my $part (@parts) { | |||||||||||||||||||||||||||||
| 267 | 0 | ▶ | next if $part !~ s/^$cmd\s+//; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 268 | 0 | my $options_href | |||||||||||||||||||||||||||||
| 269 | = $self->get_shell_options( options => $part . " " . $options ); | ||||||||||||||||||||||||||||||
| 270 | 0 | $part = "$cmd " . join( " ", values %{$options_href} ); | |||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||
| 273 | # remove trailing semicolon | ||||||||||||||||||||||||||||||
| 274 | 0 | pop @parts; | |||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||
| 276 | # join parts and return | ||||||||||||||||||||||||||||||
| 277 | 0 | $cmd = join( " ", @parts ); | |||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||
| 279 | 0 | return $cmd; | |||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | sub get_shell_options { | ||||||||||||||||||||||||||||
|
Subroutine
get_shell_options: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 283 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 284 | 0 | my %par = @_; | |||||||||||||||||||||||||||||
| 285 | 0 | my ($options) = @par{'options'}; | |||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||
| 287 | 0 | my %options; | |||||||||||||||||||||||||||||
| 288 | 0 | ▶ | my @words = map { /\s/ ? "'$_'" : $_ } $self->get_shell_words($options); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||
| 290 | 0 | my $opt; | |||||||||||||||||||||||||||||
| 291 | 0 | ▶ | for ( my $i = 0; $i < @words; ++$i ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | $words[$i] = "'$words[$i]'" if $words[$i] =~ /\s/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if ( $words[$i] =~ /^(-+\D.*)/ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||
| 295 | # why \D? Answer: minus followed by a number is | ||||||||||||||||||||||||||||||
| 296 | # surley a value, no option. | ||||||||||||||||||||||||||||||
| 297 | 0 | $opt = $1; | |||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if ( $i + 1 != @words and $words[ $i + 1 ] !~ /^-/ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i + 1 != @words and not $words[$i + 1] =~ /^-/
MC/DC0%0/2
$i + 1 != @words and not $words[$i + 1] =~ /^-/
$i + 1 != @words
not $words[$i + 1] =~ /^-/
Truth table0%0/3
A and not(B)
A= $i + 1 != @wordsB= not $words[$i + 1] =~ /^-/
| |||||||||||||||||||||||||||||||
| 299 | 0 | $options{$opt} = "$opt $words[$i+1]"; | |||||||||||||||||||||||||||||
| 300 | 0 | ++$i; | |||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||
| 302 | else { | ||||||||||||||||||||||||||||||
| 303 | 0 | $options{$opt} = "$opt"; | |||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||
| 306 | else { | ||||||||||||||||||||||||||||||
| 307 | 0 | $options{$opt} .= " " . $words[$i]; | |||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||
| 311 | 0 | return \%options; | |||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||
| 314 | # This subroutine is taken from "shellwords.pl" (standard Perl | ||||||||||||||||||||||||||||||
| 315 | # library) and slightly modified (mainly usage of lexical | ||||||||||||||||||||||||||||||
| 316 | # variables instead of globals). | ||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | sub get_shell_words { | ||||||||||||||||||||||||||||
|
Subroutine
get_shell_words: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 319 | 0 | my $thing = shift; | |||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | local ($_) = join( '', @_ ) if @_; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||
| 323 | 0 | my ( @words, $snippet, $field ); | |||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||
| 325 | 0 | s/^\s+//; | |||||||||||||||||||||||||||||
| 326 | 0 | ▶ | while ( $_ ne '' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 327 | 0 | $field = ''; | |||||||||||||||||||||||||||||
| 328 | 0 | for ( ;; ) { | |||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if (s/^"(([^"\\]|\\.)*)"//) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 330 | 0 | ( $snippet = $1 ) =~ s#\\(.)#$1#g; | |||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||
| 332 | elsif (/^"/) { | ||||||||||||||||||||||||||||||
| 333 | 0 | die "Unmatched double quote: $_\n"; | |||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||
| 335 | elsif (s/^'(([^'\\]|\\.)*)'//) { | ||||||||||||||||||||||||||||||
| 336 | 0 | ( $snippet = $1 ) =~ s#\\(.)#$1#g; | |||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||
| 338 | elsif (/^'/) { | ||||||||||||||||||||||||||||||
| 339 | 0 | die "Unmatched single quote: $_\n"; | |||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||
| 341 | elsif (s/^\\(.)//) { | ||||||||||||||||||||||||||||||
| 342 | 0 | $snippet = $1; | |||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||
| 344 | elsif (s/^([^\s\\'"]+)//) { | ||||||||||||||||||||||||||||||
| 345 | 0 | $snippet = $1; | |||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||
| 347 | else { | ||||||||||||||||||||||||||||||
| 348 | 0 | s/^\s+//; | |||||||||||||||||||||||||||||
| 349 | 0 | last; | |||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||
| 351 | 0 | $field .= $snippet; | |||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||
| 353 | 0 | push( @words, $field ); | |||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||
| 356 | 0 | return @words; | |||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | sub apply_command_template { | ||||||||||||||||||||||||||||
|
Subroutine
apply_command_template: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 360 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 361 | 0 | my %par = @_; | |||||||||||||||||||||||||||||
| 362 | 0 | my ( $template, $opts ) = @par{ 'template', 'opts' }; | |||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||
| 364 | 0 | $template =~ s/<(.*?)>/__DVDRIP_REPEATED_GROUP__/; | |||||||||||||||||||||||||||||
| 365 | 0 | my ($group_tmpl) = "$1 "; | |||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||
| 367 | 0 | my $opts_href = shift @{$opts}; | |||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||
| 369 | 0 | $template = $self->apply_template( | |||||||||||||||||||||||||||||
| 370 | template => $template, | ||||||||||||||||||||||||||||||
| 371 | opts_href => $opts_href, | ||||||||||||||||||||||||||||||
| 372 | ); | ||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||
| 374 | 0 | my $group = ""; | |||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||
| 376 | 0 | foreach my $group_opts_href ( @{$opts} ) { | |||||||||||||||||||||||||||||
| 377 | $opts_href->{$_} = $group_opts_href->{$_} | ||||||||||||||||||||||||||||||
| 378 | 0 | for keys %{$group_opts_href}; | |||||||||||||||||||||||||||||
| 379 | 0 | $group .= $self->apply_template( | |||||||||||||||||||||||||||||
| 380 | template => $group_tmpl, | ||||||||||||||||||||||||||||||
| 381 | opts_href => $opts_href, | ||||||||||||||||||||||||||||||
| 382 | ); | ||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||
| 385 | 0 | $template =~ s/__DVDRIP_REPEATED_GROUP__/$group/; | |||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||
| 387 | 0 | return $template; | |||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | sub apply_template { | ||||||||||||||||||||||||||||
|
Subroutine
apply_template: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 391 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 392 | 0 | my %par = @_; | |||||||||||||||||||||||||||||
| 393 | 0 | my ( $template, $opts_href ) = @par{ 'template', 'opts_href' }; | |||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||
| 395 | 0 | $template =~ s{\%(\(.*?\)|.)}{ | |||||||||||||||||||||||||||||
| 396 | 0 | my $var = $1; | |||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if ( $var =~ s/^\((.*)\)$/$1/ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 398 | 0 | $var =~ s/\%(.)/$opts_href->{$1}/g; | |||||||||||||||||||||||||||||
| 399 | 0 | my $eval = $var; | |||||||||||||||||||||||||||||
| 400 | 0 | $var = eval $eval; | |||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 402 | 0 | my $err = $@; | |||||||||||||||||||||||||||||
| 403 | 0 | $err =~ s/at\s+\(.*//; | |||||||||||||||||||||||||||||
| 404 | 0 | warn "Perl expression ( $eval ) => $err"; | |||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||
| 406 | } else { | ||||||||||||||||||||||||||||||
| 407 | 0 | $var = $opts_href->{$var}; | |||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||
| 409 | 0 | $var; | |||||||||||||||||||||||||||||
| 410 | }eg; | ||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||
| 412 | 0 | return $template; | |||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | sub search_perl_inc { | ||||||||||||||||||||||||||||
|
Subroutine
search_perl_inc: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 416 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 417 | 0 | my %par = @_; | |||||||||||||||||||||||||||||
| 418 | 0 | my ($rel_path) = @par{'rel_path'}; | |||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||
| 420 | 0 | my $file; | |||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||
| 422 | 0 | foreach my $INC (@INC) { | |||||||||||||||||||||||||||||
| 423 | 0 | $file = "$INC/$rel_path"; | |||||||||||||||||||||||||||||
| 424 | 0 | ▶ | last if -e $file; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 425 | 0 | $file = ""; | |||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||
| 428 | 0 | return $file; | |||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||
| 431 | 1 | 1; | |||||||||||||||||||||||||||||