blib/lib/DCOP.pm

filter: Statementstmt 53.7% 29 / 54 Branchbran 26.4% 9 / 34 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 57.1% 4 / 7 Podpod 100% 2 / 2 totaltotal 42.9% 46 / 107 CC 21 SCAR 38.8
CC
21
Cov
43%
_findSession
110.0
new
17.0
_getCommand
2.0
CRAP 48.5
↑ Summary
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
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $params{"user"} 0 1 1
30 1 ▶ if ( $self->{user} && !$params{noSession} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"user"} and not $params{"noSession"}) 0 1 1
Condition33%1/3
$self->{"user"} and not $params{"noSession"}
!ll&&!rl&&r
100
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"}
ABresult
0X0
100
111
31 0 $self->_findSession( $params{session} );
32 }
33 1 ▶ $self->{target} = $params{target} if ( $params{target} );
Branch: 1 branch
BranchTrueFalseTotal
if $params{"target"} 0 1 1
34 1 ▶ $self->{control} = $params{control} if ( $params{control} );
Branch: 1 branch
BranchTrueFalseTotal
if $params{"control"} 0 1 1
35 1 ▶ $self->{dcop} .= "--user $self->{user} " if ( $self->{user} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"user"} 0 1 1
36 1 ▶ $self->{dcop} .= "--session $self->{session} " if ( $self->{session} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"session"} 0 1 1
37 1 ▶ $self->{dcop} .= "$self->{target} " if ( $self->{target} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"target"} 0 1 1
38 1 ▶ $self->{dcop} .= "$self->{control} " if ( $self->{control} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"control"} 0 1 1
39 1 ▶ print "DCOP command is [$self->{dcop}]\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $DCOP::DEBUG 0 1 1
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
BranchTrueFalseTotal
if ($sessionParam) 0 0 0
49 0 ▶ print "session provided, using it.\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $DCOP::DEBUG 0 0 0
50 0 $self->{session} = $sessionParam;
51 0 return;
52 }
53  
54 0 ▶ print "session not provided. finding it.\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $DCOP::DEBUG 0 0 0
55 0 ▶ if ( !$self->{user} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"user"}) 0 0 0
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
BranchTrueFalseTotal
if (/DCOPserver/) 0 0 0
66 0 ▶ $session = $_ if (/DCOPserver/);
Branch: 1 branch
BranchTrueFalseTotal
if /DCOPserver/ 0 0 0
67 0 last;
68 }
69 }
70 0 ▶ $session = $1 if ( $session =~ /([._A-Za-z0-9]+)/ );
Branch: 1 branch
BranchTrueFalseTotal
if $session =~ /([._A-Za-z0-9]+)/ 0 0 0
71 0 ▶ print "user = $self->{user}, session = $session\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $DCOP::DEBUG 0 0 0
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__
↑ Summary