| 1 | package DCOP; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.038'; | |||||||||||||||||||||||||||
| 8 | 1 | our $DEBUG = 0; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | ###################################################### | ||||||||||||||||||||||||||||
| 11 | # Constructor | ||||||||||||||||||||||||||||
| 12 | # Params: | ||||||||||||||||||||||||||||
| 13 | # user - user name to be used with DCOP | ||||||||||||||||||||||||||||
| 14 | # session - (optional), if noSession is not specified and user is, the | ||||||||||||||||||||||||||||
| 15 | # first DCOP session belonging to this user is assigned | ||||||||||||||||||||||||||||
| 16 | # noSession - (optional), if user is specified, then do not request DCOP | ||||||||||||||||||||||||||||
| 17 | # to return session for user | ||||||||||||||||||||||||||||
| 18 | # target - what is the DCOP target to handle | ||||||||||||||||||||||||||||
| 19 | # control - what is the DCOP target's control to use | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 1 | my $proto = shift; | |||||||||||||||||||||||||||
| 22 | 1 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 23 | 1 | my %params = @_; | |||||||||||||||||||||||||||
| 24 | 1 | my $self = {}; | |||||||||||||||||||||||||||
| 25 | 1 | bless( $self, $class ); | |||||||||||||||||||||||||||
| 26 | 1 | chomp( my $basepath = `kde-config --expandvars --exec-prefix` ); | |||||||||||||||||||||||||||
| 27 | 1 | $self->{dcop} = "$basepath/bin/dcop "; | |||||||||||||||||||||||||||
| 28 | 1 | $self->{start} = localtime; | |||||||||||||||||||||||||||
| 29 | 1 | ▶ | $self->{user} = $params{user} if ( $params{user} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 1 | ▶ | if ( $self->{user} && !$params{noSession} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"user"} and not $params{"noSession"}
MC/DC0%0/2
$self->{"user"} and not $params{"noSession"}
$self->{"user"}
not $params{"noSession"}
Truth table33%1/3
A and not(B)
A= $self->{"user"}B= not $params{"noSession"}
| |||||||||||||||||||||||||||||
| 31 | 0 | $self->_findSession( $params{session} ); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 1 | ▶ | $self->{target} = $params{target} if ( $params{target} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 1 | ▶ | $self->{control} = $params{control} if ( $params{control} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 1 | ▶ | $self->{dcop} .= "--user $self->{user} " if ( $self->{user} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | $self->{dcop} .= "--session $self->{session} " if ( $self->{session} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | $self->{dcop} .= "$self->{target} " if ( $self->{target} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 1 | ▶ | $self->{dcop} .= "$self->{control} " if ( $self->{control} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | print "DCOP command is [$self->{dcop}]\n" if ($DEBUG); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 1 | return $self; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | ############################################### | ||||||||||||||||||||||||||||
| 44 | # Get the first session of user, else, just | ||||||||||||||||||||||||||||
| 45 | # use the provided session | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub _findSession { | ||||||||||||||||||||||||||
|
Subroutine
_findSession: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 47 | 0 | my ( $self, $sessionParam ) = @_; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($sessionParam) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | print "session provided, using it.\n" if ($DEBUG); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | $self->{session} = $sessionParam; | |||||||||||||||||||||||||||
| 51 | 0 | return; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | print "session not provided. finding it.\n" if ($DEBUG); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ( !$self->{user} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | croak( | |||||||||||||||||||||||||||
| 57 | 'No user specified. DCOP session cannot be found without an user.'); | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | my $sessions = `$self->{dcop} --user $self->{user} --list-sessions`; | |||||||||||||||||||||||||||
| 61 | 0 | my @sessions = split /\n/, $sessions; | |||||||||||||||||||||||||||
| 62 | 0 | my $session; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | for (@sessions) { | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | if (/DCOPserver/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $session = $_ if (/DCOPserver/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | last; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $session = $1 if ( $session =~ /([._A-Za-z0-9]+)/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | print "user = $self->{user}, session = $session\n" if ($DEBUG); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | $self->{session} = $session; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub _getCommand { | ||||||||||||||||||||||||||
|
Subroutine
_getCommand: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 76 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 77 | 0 | return $self->{dcop}; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 82 | 0 | my $args = join " ", @_; | |||||||||||||||||||||||||||
| 83 | 0 | chomp( my $ret = `$self->{dcop} $args` ); | |||||||||||||||||||||||||||
| 84 | 0 | return $ret; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | 1; | |||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||