| 1 | package File::DesktopEntry; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use vars qw/$AUTOLOAD/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use File::BaseDir 0.03 qw/data_files data_home/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | our $VERSION = '0.22'; | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | our $VERBOSE = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 7 | ▶ | if ($^O eq 'MSWin32') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | eval q/use Win32::Process/; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | File::DesktopEntry - Object to handle .desktop files | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | use File::DesktopEntry; | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | my $entry = File::DesktopEntry->new('firefox'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | print "Using ".$entry->Name." to open http://perl.org\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | $entry->run('http://perl.org'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | This module is designed to work with F<.desktop> files. The format of these files | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | is specified by the freedesktop "Desktop Entry" specification. This module can | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | parse these files but also knows how to run the applications defined by these | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | files. | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | For this module version 1.0 of the specification was used. | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | This module was written to support L<File::MimeInfo::Applications>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | Please remember: case is significant for the names of Desktop Entry keys. | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | =head1 VARIABLES | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | You can set the global variable C<$File::DesktopEntry::VERBOSE>. If set the | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | module prints a warning every time a command gets executed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | The global variable C<$File::DesktopEntry::LOCALE> tells you what the default | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | locale being used is. However, changing it will not change the default locale. | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | =head1 AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | All methods that start with a capital are autoloaded as C<get(KEY)> where | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | key is the autoloaded method name. | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | =item C<new(FILE)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | =item C<new(\$TEXT)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | =item C<new(NAME)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | Constructor. FILE, NAME or TEXT are optional arguments. | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | When a name is given (a string without 'C</>', 'C<\>' or 'C<.>') a lookup is | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | done using File::BaseDir. If the file found in this lookup is not writable or | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | if no file was found, the XDG_DATA_HOME path will be used when writing. | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 7 | our $LOCALE = 'C'; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # POSIX setlocale(LC_MESSAGES) not supported on all platforms | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # so we do it ourselves ... | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # string might look like lang_COUNTRY.ENCODING@MODIFIER | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | for (qw/LC_ALL LC_MESSAGES LANGUAGE LANG/) { | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 28 | ▶ | next unless $ENV{$_}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $LOCALE = $ENV{$_}; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 7 | our $_locale = _parse_lang($LOCALE); | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 19 | ▶ | my ($class, $file) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 19 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 19 | ▶ | if (! defined $file) { # initialize new file | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | $self->set(Version => '1.0', Encoding => 'UTF-8'); | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | elsif (ref $file) { $self->read($file) } # SCALAR | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 10 | elsif ($file =~ /[\/\\\.]/) { $$self{file} = $file } # file | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | $$self{file} = $class->lookup($file); # name | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | $$self{name} = $file; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 19 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 20 | ▶ | $AUTOLOAD =~ s/.*:://; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 20 | ▶ | return if $AUTOLOAD eq 'DESTROY'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | ▶ | croak "No such method: File::DesktopEntry::$AUTOLOAD" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | unless $AUTOLOAD =~ /^[A-Z][A-Za-z0-9-]+$/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | return $_[0]->get($AUTOLOAD); | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =item C<lookup(NAME)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | Returns a filename for a desktop entry with desktop file id NAME. | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | sub lookup { | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | ▶ | my (undef, $name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lookup: called CC=3 SCAR=13.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | $name .= '.desktop'; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | my $file = data_files('applications', $name); | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | ▶ | if (! $file and $name =~ /-/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $file and $name =~ /-/
MC/DC0%0/2
not $file and $name =~ /-/
not $file
$name =~ /-/
Truth table33%1/3
not(A) and B
A= not $fileB= $name =~ /-/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # name contains "-" and was not found | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my @name = split /-/, $name; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $file = data_files('applications', @name); | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | return $file; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | sub _parse_lang { | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # lang might look like lang_COUNTRY.ENCODING@MODIFIER | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 18 | ▶ | my $lang = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_lang: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 18 | ▶ | return '' if !$lang or $lang eq 'C' or $lang eq 'POSIX'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $lang or $lang eq "C" or $lang eq "POSIX"
not $lang or $lang eq "C"
MC/DC66%2/3
not $lang or $lang eq "C" or $lang eq "POSIX"
not $lang
$lang eq "C"
$lang eq "POSIX"
Truth table75%3/4
not(A) or B or C
A= not $langB= $lang eq "C"C= $lang eq "POSIX"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 7 | ▶ | $lang =~ m{^ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | ([^_@\.]+) # lang $1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | (?: _ ([^@\.]+) )? # COUNTRY $2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | (?: \. [^@]+ )? # ENCODING | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | (?: \@ (.+) )? # MODIFIER $3 | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | $}x or return ''; | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 7 | my ($l, $c, $m) = ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | 7 | ▶ | my @locale = ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$m and $c
MC/DC100%2/2
$m and $c
$m
$c
Truth table100%3/3
A and B
A= $mB= $c
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | $l, | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | ($m ? "$l\@$m" : ()), | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | ($c ? "$l\_$c" : ()), | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | (($m && $c) ? "$l\_$c\@$m" : ()) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 7 | return join '|', reverse @locale; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | =item C<wants_uris( )> | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | Returns true if the Exec string for this desktop entry specifies that the | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | application uses URIs instead of paths. This can be used to determine | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | whether an application uses a VFS library. | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | =item C<wants_list( )> | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | Returns true if the Exec string for this desktop entry specifies that the | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | application can handle multiple arguments at once. | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | sub wants_uris { | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wants_uris: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | my $exec = $self->get('Exec'); | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | croak "No Exec string defined for desktop entry" unless length $exec; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | $exec =~ s/\%\%//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | return $exec =~ /\%U/i; | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | sub wants_list { | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wants_list: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | my $exec = $self->get('Exec'); | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | ▶ | croak "No Exec string defined for desktop entry" unless length $exec; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | $exec =~ s/\%\%//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | return $exec !~ /\%[fud]/; # we default to %F if no /\%[FUD]/i is found | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | =item C<run(@FILES)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | Forks and runs the application specified in this Desktop Entry | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | with arguments FILES as a background process. Returns the pid. | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | The child process fails when this is not a Desktop Entry of type Application | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | or if the Exec key is missing or invalid. | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | If the desktop entry specifies that the program needs to be executed in a | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | terminal the $TERMINAL environment variable is used. If this variable is not | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | set C<xterm -e> is used as default. | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | (On Windows this method returns a L<Win32::Process> object.) | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | =item C<system(@FILES)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | Like C<run()> but using the C<system()> system call. | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | It only return after the application has ended. | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | =item C<exec(@FILES)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | Like C<run()> but using the C<exec()> system call. This method | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | is expected not to return but to replace the current process with the | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | application you try to run. | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | On Windows this method doesn't always work the way you want it to | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | due to the C<fork()> emulation on this platform. Try using C<run()> or | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | C<system()> instead. | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 3 | ▶ | my $pid = fork; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 3 | ▶ | return $pid if $pid; # parent process | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | unshift @_, 'exec'; goto \&_run; | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 5 | ▶ | sub system { unshift @_, 'system'; goto \&_run } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
system: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | ▶ | sub exec { unshift @_, 'exec'; goto \&_run } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | sub _run { | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 7 | ▶ | my $call = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run: called CC=14 SCAR=29.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 7 | ▶ | croak "Desktop entry is not an Application" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | unless $self->get('Type') eq 'Application'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 7 | my @exec = $self->parse_Exec(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 7 | my $t = $self->get('Terminal'); | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | 7 | ▶ | if ($t and $t eq 'true') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$t and $t eq "true"
MC/DC0%0/2
$t and $t eq "true"
$t
$t eq "true"
Truth table33%1/3
A and B
A= $tB= $t eq "true"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | my $term = $ENV{TERMINAL} || 'xterm -e'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{'TERMINAL'} || 'xterm -e'
MC/DC0%0/1
$ENV{'TERMINAL'} || 'xterm -e'
$ENV{'TERMINAL'}
Truth table0%0/2
A
A= $ENV{'TERMINAL'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | unshift @exec, _split($term); | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 7 | my $cwd; | |||||||||||||||||||||||||||||||||||||||||||||
| 237 | 7 | ▶ | if (my $path = $self->get('Path')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 3 | require Cwd; | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | 3 | $cwd = Cwd::getcwd(); | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | 3 | ▶ | chdir $path or croak "Could not change to dir: $path"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 3 | $ENV{PWD} = $path; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | 3 | ▶ | warn "Running from directory: $path\n" if $VERBOSE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 7 | ▶ | warn "Running: "._quote(@exec)."\n" if $VERBOSE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 7 | ▶ | if ($call eq 'exec') { CORE::exec {$exec[0]} @exec; exit 1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 5 | else { CORE::system {$exec[0]} @exec } | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 5 | ▶ | warn "Error: $!\n" if $VERBOSE and $?; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$File::DesktopEntry::VERBOSE and $?
MC/DC0%0/2
$File::DesktopEntry::VERBOSE and $?
$File::DesktopEntry::VERBOSE
$?
Truth table33%1/3
A and B
A= $File::DesktopEntry::VERBOSEB= $?
| |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 5 | ▶ | if (defined $cwd) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | ▶ | chdir $cwd or croak "Could not change back to dir: $cwd"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | $ENV{PWD} = $cwd; | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | =item C<parse_Exec(@FILES)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | Expands the Exec format in this desktop entry with. Returns a properly quoted | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | string in scalar context or a list of words in list context. Dies when the | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | Exec key is invalid. | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | It supports the following fields: | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | %f single file | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | %F multiple files | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | %u single url | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | %U multiple urls | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | %i Icon field prefixed by --icon | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | %c Name field, possibly translated | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | %k location of this .desktop file | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | %% literal '%' | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | If necessary this method tries to convert between paths and URLs but this | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | is not perfect. | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | Fields that are deprecated, but (still) supported by this module: | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | %d single directory | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | %D multiple directories | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | The fields C<%n>, C<%N>, C<%v> and C<%m> are deprecated and will cause a | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | warning if C<$VERBOSE> is used. Any other unknown fields will cause an error. | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | The fields C<%F>, C<%U>, C<%D> and C<%i> can only occur as separate words | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | because they expand to multiple arguments. | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | Also see L</LIMITATIONS>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | sub parse_Exec { | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 23 | ▶ | my ($self, @argv) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_Exec: called CC=27 SCAR=34.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 23 | my @format = _split( $self->get('Exec') ); | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # Check format | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 23 | my $seen = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | 23 | for (@format) { | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | 62 | my $s = $_; # copy; | |||||||||||||||||||||||||||||||||||||||||||||
| 300 | 62 | $s =~ s/\%\%//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | 62 | $seen += ($s =~ /\%[fFuUdD]/); | |||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 62 | ▶ | die "Exec key for '".$self->get('Name')."' contains " . | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $s =~ /^\%[FUD]$/ and $s =~ /\%[FUD]/
MC/DC0%0/2
not $s =~ /^\%[FUD]$/ and $s =~ /\%[FUD]/
not $s =~ /^\%[FUD]$/
$s =~ /\%[FUD]/
Truth table66%2/3
not(A) and B
A= not $s =~ /^\%[FUD]$/B= $s =~ /\%[FUD]/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | "'\%F\', '\%U' or '\%D' at the wrong place\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | if $s !~ /^\%[FUD]$/ and $s =~ /\%[FUD]/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 62 | ▶ | die "Exec key for '".$self->get('Name')."' contains " . | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | "unknown field code '$1'\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | if $s =~ /(\%[^fFuUdDnNickvm])/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 61 | ▶ | croak "Application '".$self->get('Name')."' ". | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@argv > 1 and $s =~ /\%[fud]/
MC/DC100%2/2
@argv > 1 and $s =~ /\%[fud]/
@argv > 1
$s =~ /\%[fud]/
Truth table100%3/3
A and B
A= @argv > 1B= $s =~ /\%[fud]/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | "takes only one argument" | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | if @argv > 1 and $s =~ /\%[fud]/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 60 | ▶ | warn "Exec key for '".$self->get('Name')."' contains " . | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$File::DesktopEntry::VERBOSE and $s =~ /%([nNvm])/
MC/DC0%0/2
$File::DesktopEntry::VERBOSE and $s =~ /%([nNvm])/
$File::DesktopEntry::VERBOSE
$s =~ /%([nNvm])/
Truth table33%1/3
A and B
A= $File::DesktopEntry::VERBOSEB= $s =~ /%([nNvm])/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | "deprecated field codes\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | if $VERBOSE and $s =~ /%([nNvm])/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 21 | ▶ | if ($seen == 0) { push @format, '%F' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | elsif ($seen > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # not allowed according to the spec | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | warn "Exec key for '".$self->get('Name')."' contains " . | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | "multiple fields for files or uris.\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # Expand format | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 21 | my @exec; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 21 | for (@format) { | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | 67 | ▶ | if (/^\%([FUD])$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 17 | ▶ | push @exec, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | ($1 eq 'F') ? _paths(@argv) : | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | ($1 eq 'U') ? _uris(@argv) : _dirs(@argv) ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | elsif ($_ eq '%i') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | my $icon = $self->get('Icon'); | |||||||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | ▶ | push @exec, '--icon', $icon if defined($icon); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | else { # expand with word ( e.g. --input=%f ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 49 | my $bad; | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | 49 | s/\%(.)/ | |||||||||||||||||||||||||||||||||||||||||||||
| 342 | ($1 eq '%') ? '%' : | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | ($1 eq 'f') ? (_paths(@argv))[0] : | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | ($1 eq 'u') ? (_uris(@argv) )[0] : | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | ($1 eq 'd') ? (_dirs(@argv) )[0] : | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | ($1 eq 'c') ? $self->get('Name') : | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 11 | ▶ | ($1 eq 'k') ? $$self{file} : '' ; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | /eg; | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 49 | push @exec, $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 21 | ▶ | if (wantarray and $^O eq 'MSWin32') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
wantarray and $^O eq "MSWin32"
MC/DC0%0/2
wantarray and $^O eq "MSWin32"
wantarray
$^O eq "MSWin32"
Truth table66%2/3
A and B
A= wantarrayB= $^O eq "MSWin32"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # Win32 requires different quoting *sigh* | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | for (grep /"/, @exec) { | |||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | s#"#\\"#g; | |||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $_ = qq#"$_"#; | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 21 | ▶ | return wantarray ? (@exec) : _quote(@exec); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | sub _split { | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # Reverse quoting and break string in words. | ||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # It allows single quotes to be used, which the spec doesn't. | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 46 | ▶ | my $string = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 46 | my @args; | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | 46 | ▶ | while ($string =~ /\S/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 126 | ▶ | if ($string =~ /^(['"])/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 33 | my $q = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | 33 | $string =~ s/^($q(\\.|[^$q])*$q)//s; | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | 33 | ▶ | push @args, $1 if defined $1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 126 | $string =~ s/(\S*)\s*//; # also fallback for above regex | |||||||||||||||||||||||||||||||||||||||||||||
| 376 | 126 | ▶ | push @args, $1 if defined $1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 46 | @args = grep length($_), @args; | |||||||||||||||||||||||||||||||||||||||||||||
| 379 | 46 | for (@args) { | |||||||||||||||||||||||||||||||||||||||||||||
| 380 | 127 | ▶ | if (/^(["'])(.*)\1$/s) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 32 | $_ = $2; | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | 32 | s/\\(["`\$\\])/$1/g; # remove backslashes | |||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 46 | return @args; | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | sub _quote { | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # Turn a list of words in a properly quoted Exec key | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 32 | ▶ | my @words = @_; # copy; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quote: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | return join ' ', map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 32 | ▶ | if (/([\s"'`\\<>~\|\&;\$\*\?#\(\)])/) { # reserved chars | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 19 | s/(["`\$\\])/\\$1/g; # add backslashes | |||||||||||||||||||||||||||||||||||||||||||||
| 394 | 19 | $_ = qq/"$_"/; # add quotes | |||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 91 | $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 397 | } grep defined($_), @words; | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | sub _paths { | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | # Check if we need to convert file:// uris to paths | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | # support file:/path file://localhost/path and file:///path | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # A path like file://host/path is replace by smb://host/path | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # which the app probably can't open | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 21 | ▶ | $_ = _uri_to_path($_) if s#^file:(?://localhost/+|/|///+)(?!/)#/#i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paths: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 19 | s#^file://(?!/)#smb://#i; | |||||||||||||||||||||||||||||||||||||||||||||
| 408 | 19 | $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 409 | } @_; | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | sub _dirs { | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # Like _paths, but makes the path a directory | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 2 | ▶ | if (-d $_) { $_ } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dirs: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 416 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | my ($vol, $dirs, undef) = File::Spec->splitpath($_); | |||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | File::Spec->catpath($vol, $dirs, ''); | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } _paths(@_); | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | sub _uris { | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # Convert paths to file:// uris | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 4 | ▶ | m#^\w+://# ? $_ : 'file://'._path_to_uri($_); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_uris: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } @_; | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | sub _uri_to_path { | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 7 | ▶ | my $x = Encode::encode('utf8', $_); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_uri_to_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 7 | $x = uri_unescape($x); | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | 7 | return Encode::decode('utf8', $x); | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | sub _path_to_uri { | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 3 | ▶ | my $path = File::Spec->rel2abs(shift); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_path_to_uri: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 3 | my ($volume, $directories, $file) = File::Spec->splitpath($path); | |||||||||||||||||||||||||||||||||||||||||||||
| 439 | 3 | my $uri = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # actually, on Windows, File URIs look like this: | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # file:///C:/Program%20Files/MyApp/app.exe | ||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # ref: https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/ | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 3 | ▶ | if ($volume) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $uri .= '/' . $volume; | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 3 | $uri .= join '/', map { uri_escape_utf8($_) } File::Spec->splitdir($directories . $file); | |||||||||||||||||||||||||||||||||||||||||||||
| 448 | 3 | return $uri; | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||
| 451 | =item C<get(KEY)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||
| 453 | =item C<get(GROUP, KEY)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||
| 455 | Get a value for KEY from GROUP. If GROUP is not specified 'Desktop Entry' is | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | used. All values are treated as string, so e.g. booleans will be returned as | ||||||||||||||||||||||||||||||||||||||||||||||
| 457 | the literal strings "true" and "false". | ||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||
| 459 | When KEY does not contain a language code you get the translation in the | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | current locale if available or a sensible default. The request a specific | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | language you can add the language part. E.g. C<< $entry->get('Name[nl_NL]') >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | can return either the value of the 'Name[nl_NL]', the 'Name[nl]' or the 'Name' | ||||||||||||||||||||||||||||||||||||||||||||||
| 463 | key in the Desktop Entry file. Exact language parsing order can be found in the | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | spec. To force you get the untranslated key use either 'Name[C]' or | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 'Name[POSIX]'. | ||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # used for (un-)escaping strings | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 7 | my %Chr = (s => ' ', n => "\n", r => "\r", t => "\t", '\\' => '\\'); | |||||||||||||||||||||||||||||||||||||||||||||
| 471 | 7 | my %Esc = reverse %Chr; | |||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||
| 473 | sub get { | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 115 | ▶ | my ($self, $group, $key) = | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=8 SCAR=20.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | (@_ == 2) ? ($_[0], '', $_[1]) : (@_) ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 115 | my $locale = $_locale; | |||||||||||||||||||||||||||||||||||||||||||||
| 477 | 115 | ▶ | if ($key =~ /^(.*?)\[(.*?)\]$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 6 | $key = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 479 | 6 | $locale = _parse_lang($2); | |||||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 115 | my @lang = split /\|/, $locale; | |||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # Get values that match locale from group | ||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 115 | ▶ | $self->read() unless $$self{groups}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 115 | my $i = $self->_group($group); | |||||||||||||||||||||||||||||||||||||||||||||
| 487 | 115 | ▶ | return undef unless defined $i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 114 | ▶ | my $lang = join('|', map quotemeta($_), @lang) || 'C'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
join('|', map(quotemeta($_), @lang)) || 'C'
MC/DC100%1/1
join('|', map(quotemeta($_), @lang)) || 'C'
join('|', map(quotemeta($_), @lang))
Truth table100%2/2
A
A= join('|', map(quotemeta($_), @lang))
| |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 114 | my %matches = ( $$self{groups}[$i] =~ | |||||||||||||||||||||||||||||||||||||||||||||
| 490 | /^(\Q$key\E\[(?:$lang)\]|\Q$key\E)[^\S\n]*=[^\S\n]*(.*?)\s*$/gm ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 114 | ▶ | return undef unless keys %matches; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # Find preferred value | ||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 98 | my @keys = (map($key."[$_]", @lang), $key); | |||||||||||||||||||||||||||||||||||||||||||||
| 495 | 98 | my ($value) = grep defined($_), @matches{@keys}; | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||
| 497 | # Parse string (replace \n, \t, etc.) | ||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 98 | ▶ | $value =~ s/\\(.)/$Chr{$1}||$1/eg; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 98 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||
| 502 | sub _group { # returns index for a group name | ||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 151 | ▶ | my ($self, $group, $dont_die) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_group: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 151 | ▶ | $group ||= 'Desktop Entry'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$group ||= "Desktop Entry"
MC/DC100%1/1
$group ||= "Desktop Entry"
$group
Truth table100%2/2
A
A= $group
| |||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 151 | ▶ | croak "Group name contains invalid characters: $group" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | if $group =~ /[\[\]\r\n]/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 151 | for my $i (0 .. $#{$$self{groups}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 508 | 158 | ▶ | return $i if $$self{groups}[$i] =~ /^\[\Q$group\E\]/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 7 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||
| 513 | =item C<set(KEY =E<gt> VALUE, ...)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||
| 515 | =item C<set(GROUP, KEY =E<gt> VALUE, ...)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||
| 517 | Set values for one or more keys. If GROUP is not given "Desktop Entry" is used. | ||||||||||||||||||||||||||||||||||||||||||||||
| 518 | All values are treated as strings, backslashes, newlines and tabs are escaped. | ||||||||||||||||||||||||||||||||||||||||||||||
| 519 | To set a boolean key you need to use the literal strings "true" and "false". | ||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||
| 521 | Unlike the C<get()> call languages are not handled automatically for C<set()>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 522 | KEY should include the language part if you want to set a translation. | ||||||||||||||||||||||||||||||||||||||||||||||
| 523 | E.g. C<< $entry->set("Name[nl_NL]" => "Tekst Verwerker") >> will set a Dutch | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | translation for the Name key. Using either "Name[C]" or "Name[POSIX]" will | ||||||||||||||||||||||||||||||||||||||||||||||
| 525 | be equivalent with not giving a language argument. | ||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||
| 527 | When setting the Exec key without specifying a group it will be parsed | ||||||||||||||||||||||||||||||||||||||||||||||
| 528 | and quoted correctly as required by the spec. You can use quoted arguments | ||||||||||||||||||||||||||||||||||||||||||||||
| 529 | to include whitespace in a argument, escaping whitespace does not work. | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | To circumvent this quoting explicitly give the group name 'Desktop Entry'. | ||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||
| 532 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | sub set { | ||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 34 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 34 | ▶ | my ($group, @data) = ($#_ % 2) ? (undef, @_) : (@_) ; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 34 | ▶ | $self->read() unless $$self{groups} or ! $$self{file}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"groups"} or not $self->{"file"}
MC/DC100%2/2
$self->{"groups"} or not $self->{"file"}
$self->{"groups"}
not $self->{"file"}
Truth table100%3/3
A or not(B)
A= $self->{"groups"}B= not $self->{"file"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 34 | my $i = $self->_group($group); | |||||||||||||||||||||||||||||||||||||||||||||
| 540 | 34 | ▶ | unless (defined $i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 6 | ▶ | $group ||= 'Desktop Entry'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$group ||= "Desktop Entry"
MC/DC100%1/1
$group ||= "Desktop Entry"
$group
Truth table100%2/2
A
A= $group
| |||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 6 | push @{$$self{groups}}, "[$group]\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 543 | 6 | $i = $#{$$self{groups}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 34 | ▶ | while (@data) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 48 | my ($k, $v) = splice(@data, 0, 2); | |||||||||||||||||||||||||||||||||||||||||||||
| 548 | 48 | $k =~ s/\[(C|POSIX)\]$//; # remove default locale | |||||||||||||||||||||||||||||||||||||||||||||
| 549 | 48 | my ($word) = ($k =~ /^(.*?)(\[.*?\])?$/); | |||||||||||||||||||||||||||||||||||||||||||||
| 550 | # separate key and locale | ||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 48 | ▶ | croak "BUG: Key missing: $k" unless length $word; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 48 | ▶ | carp "Key contains invalid characters: $k" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 553 | if $word =~ /[^A-Za-z0-9-]/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 48 | ▶ | $v = _quote( _split($v) ) if ! $group and $k eq 'Exec'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $group and $k eq "Exec"
MC/DC100%2/2
not $group and $k eq "Exec"
not $group
$k eq "Exec"
Truth table100%3/3
not(A) and B
A= not $groupB= $k eq "Exec"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # Exec key needs extra quoting | ||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 48 | $v =~ s/([\\\n\r\t])/\\$Esc{$1}/g; # add escapes | |||||||||||||||||||||||||||||||||||||||||||||
| 557 | 48 | ▶ | $$self{groups}[$i] =~ s/^\Q$k\E=.*$/$k=$v/m and next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 25 | $$self{groups}[$i] .= "$k=$v\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||
| 562 | =item C<text()> | ||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||
| 564 | Returns the (modified) text of the file. | ||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||
| 568 | sub text { | ||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 3 | ▶ | $_[0]->read() unless $_[0]{groups}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text: called CC=4 SCAR=13.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 3 | ▶ | return '' unless $_[0]{groups}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 3 | s/\n?$/\n/ for @{$_[0]{groups}}; # just to be sure | |||||||||||||||||||||||||||||||||||||||||||||
| 572 | 3 | return join "\n", @{$_[0]{groups}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||
| 575 | =item C<read(FILE)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||
| 577 | =item C<read(\$SCALAR)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||
| 579 | Read Desktop Entry data from file or memory buffer. | ||||||||||||||||||||||||||||||||||||||||||||||
| 580 | Without argument defaults to file given at constructor. | ||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||
| 582 | If you gave a file, text buffer or name to the constructor this method will | ||||||||||||||||||||||||||||||||||||||||||||||
| 583 | be called automatically. | ||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||
| 585 | =item C<read_fh(IO)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||
| 587 | Read Desktop Entry data from filehandle or IO object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||
| 589 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||
| 591 | sub read { | ||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 14 | ▶ | my ($self, $file) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 14 | ▶ | $file ||= $$self{file}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$file ||= $self->{"file"}
MC/DC0%0/2
$file ||= $self->{"file"}
$file
$self->{"file"}
Truth table66%2/3
A ||= B
A= $fileB= $self->{"file"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 14 | ▶ | croak "DesktopEntry has no filename to read from" unless length $file; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 14 | my $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 597 | 14 | ▶ | unless (ref $file) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 10 | ▶ | open $fh, "<$file" or croak "Could not open file: $file"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 600 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 4 | ▶ | open $fh, '<', $file or croak "Could not open SCALAR ref !?"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 14 | binmode $fh, ':utf8'; | |||||||||||||||||||||||||||||||||||||||||||||
| 604 | 14 | $self->read_fh($fh); | |||||||||||||||||||||||||||||||||||||||||||||
| 605 | 14 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||
| 608 | sub read_fh { | ||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 14 | ▶ | my ($self, $fh) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_fh: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 14 | $$self{groups} = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||
| 612 | # Read groups | ||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 14 | my $group = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 614 | 14 | ▶ | while (my $l = <$fh>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 437 | $l =~ s/\r?\n$/\n/; # DOS to Unix conversion | |||||||||||||||||||||||||||||||||||||||||||||
| 616 | 437 | ▶ | if ($l =~ /^\[(.*?)\]\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 32 | ▶ | push @{$$self{groups}}, $group | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 618 | if length $group; | ||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 32 | $group = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 437 | $group .= $l; | |||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 14 | push @{$$self{groups}}, $group; | |||||||||||||||||||||||||||||||||||||||||||||
| 624 | 14 | s/\n\n$/\n/ for @{$$self{groups}}; # remove last empty line | |||||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||||||
| 626 | # Some checks | ||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 14 | for (qw/Name Type/) { | |||||||||||||||||||||||||||||||||||||||||||||
| 628 | 28 | ▶ | carp "Required key missing in Desktop Entry: $_" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 629 | unless defined $self->get($_); | ||||||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 14 | my $enc = $self->get('Encoding'); | |||||||||||||||||||||||||||||||||||||||||||||
| 632 | 14 | ▶ | carp "Desktop Entry uses unsupported encoding: $enc" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$enc and $enc ne "UTF-8"
MC/DC0%0/2
$enc and $enc ne "UTF-8"
$enc
$enc ne "UTF-8"
Truth table66%2/3
A and B
A= $encB= $enc ne "UTF-8"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 633 | if $enc and $enc ne 'UTF-8'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||
| 636 | =item C<write(FILE)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||
| 638 | Write the Desktop Entry data to FILE. Without arguments it writes to | ||||||||||||||||||||||||||||||||||||||||||||||
| 639 | the filename given to the constructor if any. | ||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||
| 641 | The keys Name and Type are required. Type can be either C<Application>, | ||||||||||||||||||||||||||||||||||||||||||||||
| 642 | C<Link> or C<Directory>. For an application set the optional key C<Exec>. For | ||||||||||||||||||||||||||||||||||||||||||||||
| 643 | a link set the C<URL> key. | ||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||
| 645 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||
| 647 | # Officially we should check lines end with LF - this is \n on Unix | ||||||||||||||||||||||||||||||||||||||||||||||
| 648 | # but on Windows \n is CR LF, which breaks the spec | ||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||
| 650 | sub write { | ||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=13 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 1 | ▶ | my $file = shift || $$self{file}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self->{'file'}
MC/DC0%0/2
shift() || $self->{'file'}
shift()
$self->{'file'}
Truth table33%1/3
A || B
A= shift()B= $self->{'file'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 1 | ▶ | unless ($$self{groups}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | ▶ | if ($$self{file}) { $self->read() } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | else { croak "Can not write empty Desktop Entry file" } | |||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||
| 658 | # Check keys | ||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 1 | for (qw/Name Type/) { | |||||||||||||||||||||||||||||||||||||||||||||
| 660 | 2 | ▶ | croak "Can not write a desktop file without a $_ field" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 661 | unless defined $self->get($_); | ||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 1 | $self->set(Version => '1.0', Encoding => 'UTF-8'); | |||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||
| 665 | # Check file writable | ||||||||||||||||||||||||||||||||||||||||||||||
| 666 | $file = $self->_data_home_file | ||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 1 | ▶ | if (! $file or ! -w $file) and defined $$self{name}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not $file && -w $file and defined $self->{"name"}
$file && -w $file
MC/DC0%0/3
not $file && -w $file and defined $self->{"name"}
$file
-w $file
defined $self->{"name"}
Truth table20%1/5
not(A && B) and C
A= $fileB= -w $fileC= defined $self->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 1 | ▶ | croak "No file given for writing Desktop Entry" unless length $file; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||
| 670 | # Write file | ||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 1 | s/\n?$/\n/ for @{$$self{groups}}; # just to be sure | |||||||||||||||||||||||||||||||||||||||||||||
| 672 | 1 | ▶ | open OUT, ">$file" or die "Could not write file: $file\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 1 | ▶ | binmode OUT, ':utf8' unless $] < 5.008; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 1 | print OUT join "\n", @{$$self{groups}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 675 | 1 | close OUT; | |||||||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||
| 678 | sub _data_home_file { | ||||||||||||||||||||||||||||||||||||||||||||||
| 679 | # create new file name in XDG_DATA_HOME from name | ||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_data_home_file: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 1 | my @parts = split /-/, $$self{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 682 | 1 | $parts[-1] .= '.desktop'; | |||||||||||||||||||||||||||||||||||||||||||||
| 683 | 1 | my $dir = data_home('applications', @parts[0 .. $#parts-1]); | |||||||||||||||||||||||||||||||||||||||||||||
| 684 | 1 | ▶ | unless (-d $dir) { # create dir if it doesn't exist | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 1 | require File::Path; | |||||||||||||||||||||||||||||||||||||||||||||
| 686 | 1 | File::Path::mkpath($dir); | |||||||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 1 | return data_home('applications', @parts); | |||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||
| 691 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||
| 693 | =head2 Backwards Compatibility | ||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||
| 695 | Methods supported for backwards compatibility with 0.02. | ||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||
| 697 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||
| 699 | =item C<new_from_file(FILE)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||
| 701 | Alias for C<new(FILE)>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||||||
| 703 | =item C<new_from_data(TEXT)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||||||
| 705 | Alias for C<new(\$TEXT)>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||||||
| 707 | =item C<get_value(NAME, GROUP, LANG)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||
| 709 | Identical to C<get(GROUP, "NAME[LANG]")>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 710 | LANG defaults to 'C', GROUP is optional. | ||||||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||||||
| 712 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 1 | ▶ | sub new_from_file { $_[0]->new($_[1]) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 2 | ▶ | sub new_from_data { $_[0]->new(\$_[1]) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||
| 718 | sub get_value { | ||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 2 | ▶ | my ($self, $key, $group, $locale) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_value: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 2 | ▶ | $locale ||= 'C'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$locale ||= "C"
MC/DC0%0/1
$locale ||= "C"
$locale
Truth table50%1/2
A
A= $locale
| |||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 2 | $key .= "[$locale]"; | |||||||||||||||||||||||||||||||||||||||||||||
| 722 | 2 | ▶ | $group ? $self->get($group, $key) : $self->get($key); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||||||
| 725 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||
| 727 | =head1 NON-UNIX PLATFORMS | ||||||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||||||
| 729 | This module has a few bits of code to make it work on Windows. It handles | ||||||||||||||||||||||||||||||||||||||||||||||
| 730 | C<file://> uri a bit different and it uses L<Win32::Process>. On other | ||||||||||||||||||||||||||||||||||||||||||||||
| 731 | platforms your mileage may vary. | ||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||
| 733 | Please note that the specification is targeting Unix platforms only and | ||||||||||||||||||||||||||||||||||||||||||||||
| 734 | will only have limited relevance on other platforms. Any platform-dependent | ||||||||||||||||||||||||||||||||||||||||||||||
| 735 | behavior in this module should be considered an extension of the spec. | ||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||
| 737 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 7 | ▶ | if ($^O eq 'MSWin32') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 740 | # Re-define some modules - I assume this block gets optimized away by the | ||||||||||||||||||||||||||||||||||||||||||||||
| 741 | # interpreter when not running on windows. | ||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 7 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||||||
| 744 | # Wrap _paths() to remove first '/' | ||||||||||||||||||||||||||||||||||||||||||||||
| 745 | # As a special case translate SMB file:// uris | ||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | my $_paths = \&_paths; | |||||||||||||||||||||||||||||||||||||||||||||
| 747 | *_paths = sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 748 | my @paths = map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | ▶ | s#^file:////(?!/)#smb://#; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 751 | } @_; | ||||||||||||||||||||||||||||||||||||||||||||||
| 752 | map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | s#^/+([a-z]:/)#$1#i; | |||||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 755 | } &$_paths(@paths); | ||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||||||
| 758 | # Wrap _uris() to remove '\' in path | ||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | my $_uris = \&_uris; | |||||||||||||||||||||||||||||||||||||||||||||
| 760 | *_uris = sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 761 | map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | ▶ | s#\\#/#g; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 764 | } &$_uris(@_); | ||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||
| 767 | # Using Win32::Process because fork is not native on win32 | ||||||||||||||||||||||||||||||||||||||||||||||
| 768 | # Effect is that closing an application spawned with fork | ||||||||||||||||||||||||||||||||||||||||||||||
| 769 | # can kill the parent process as well when using Gtk2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 770 | *run = sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | ▶ | my ($self, @files) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | my $cmd = eval { $self->parse_Exec(@files) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | ▶ | warn $@ if $@; # run should not die | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | my $bin = (_split($cmd))[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | ▶ | unless (-f $bin) { # we need the real binary path | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | my ($b) = grep {-f $_} | |||||||||||||||||||||||||||||||||||||||||||||
| 779 | map File::Spec->catfile($_, $bin), | ||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | split /[:;]/, $ENV{PATH} ; | |||||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | ▶ | if (-f $b) { $bin = $b } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 782 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | warn "Could not find application: $bin\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | ▶ | my $dir = $self->get('Path') || '.'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->get('Path') || '.'
MC/DC0%0/1
$self->get('Path') || '.'
$self->get('Path')
Truth table0%0/2
A
A= $self->get('Path')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | ▶ | if ($VERBOSE) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | ▶ | warn "Running from directory: $dir" unless $dir eq '.'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | warn "Running: $cmd\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | my $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | Win32::Process::Create( | |||||||||||||||||||||||||||||||||||||||||||||
| 797 | $obj, $bin, $cmd, 0, &NORMAL_PRIORITY_CLASS, $dir ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 798 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | ▶ | warn $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||||||
| 807 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||