File Coverage

blib/lib/Protocol/DBus/Path.pm
Criterion Covered Total %
statement 16 23 69.5
branch 2 6 33.3
condition 2 8 25.0
subroutine 6 6 100.0
pod 0 2 0.0
total 26 45 57.7


line stmt bran cond sub pod time code
1             package Protocol::DBus::Path;
2              
3 4     4   20 use strict;
  4         7  
  4         82  
4 4     4   13 use warnings;
  4         4  
  4         65  
5              
6 4     4   1239 use Protocol::DBus::Address ();
  4         8  
  4         68  
7              
8 4     4   21 use constant _DEFAULT_SYSTEM_MESSAGE_BUS => 'unix:path=/var/run/dbus/system_bus_socket';
  4         5  
  4         634  
9              
10             # NB: If this returns “autolaunch:”, then the system should use
11             # platform-specific methods of locating a running D-Bus session server,
12             # or starting one if a running instance cannot be found.
13             sub login_session_message_bus {
14 1     1 0 3 my $addr = $ENV{'DBUS_SESSION_BUS_ADDRESS'};
15              
16 1 50 33     8 if (!$addr && ($^O eq 'darwin')) {
17 0         0 my $path = $ENV{'DBUS_LAUNCHD_SESSION_BUS_SOCKET'};
18              
19             # OK, let’s *really* stretch …
20 0   0     0 $path ||= readpipe( "launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET" );
21 0         0 chomp $path;
22              
23 0 0       0 if ($path) {
24 0         0 chomp $path;
25              
26 0         0 $addr = "unix:path=$path";
27             }
28             }
29              
30 1 50       9 die "Found no login session message bus address!" if !$addr;
31              
32 0         0 return Protocol::DBus::Address::parse($addr);
33             }
34              
35             sub system_message_bus {
36 1   50 1 0 10 return Protocol::DBus::Address::parse( $ENV{'DBUS_SYSTEM_BUS_ADDRESS'} || _DEFAULT_SYSTEM_MESSAGE_BUS() );
37             }
38              
39             1;