| 1 | # Copyright 2010, 2011, 2012, 2013, 2014, 2017 Kevin Ryde | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # This file is part of X11-Protocol-Other. | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # X11-Protocol-Other is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 6 | # it under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||
| 7 | # Free Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||
| 8 | # version. | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # X11-Protocol-Other is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||
| 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||
| 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||||||||||||||||||
| 13 | # for more details. | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||
| 16 | # with X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | package X11::Protocol::GrabServer; | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | BEGIN { require 5 } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 24 | # weaken() if available, which means new enough Perl to have weakening, | ||||||||||||||||||||||||||||
| 25 | # and Scalar::Util with its XS code | ||||||||||||||||||||||||||||
| 26 | 1 | ▶ | eval "use Scalar::Util 'weaken'; 1" | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Branch: 1 branch
Condition33%1/3
eval "use Scalar::Util 'weaken'; 1" or eval "\n#line 28 \"/home/cpancover/.cpan/build/X11-Protocol-Other-31-0/blib/lib/X11/Protocol/GrabServer.pm\"\nsub weaken {} # otherwise noop\n"
MC/DC0%0/2
eval "use Scalar::Util 'weaken'; 1" or eval "\n#line 28 \"/home/cpancover/.cpan/build/X11-Protocol-Other-31-0/blib/lib/X11/Protocol/GrabServer.pm\"\nsub weaken {} # otherwise noop\n"
eval "use Scalar::Util 'weaken'; 1"
eval "\n#line 28 \"/home/cpancover/.cpan/build/X11-Protocol-Other-31-0/blib/lib/X11/Protocol/GrabServer.pm\"\nsub weaken {} # otherwise noop\n"
Truth table33%1/3
A or B
A= eval "use Scalar::Util 'weaken'; 1"B= eval "\n#line 28 \"/home/cpancover/.cpan/build/X11-Protocol-Other-31-0/blib/lib/X11/Protocol/GrabServer.pm\"\nsub weaken {} # otherwise noop\n"
| |||||||||||||||||||||||||||||
| 27 | or eval "\n#line ".(__LINE__+1)." \"".__FILE__."\"\n" . <<'HERE' or die; | ||||||||||||||||||||||||||||
| 28 | sub weaken {} # otherwise noop | ||||||||||||||||||||||||||||
| 29 | HERE | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||
| 33 | #use Smart::Comments; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 1 | $VERSION = 31; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 0 | my ($class, $X) = @_; | |||||||||||||||||||||||||||
| 40 | ### GrabServer-object new(): "$X" | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if (! defined $X) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | croak "No X connection given"; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 0 | my $self = bless { X => $X }, $class; | |||||||||||||||||||||||||||
| 45 | 0 | weaken ($self->{'X'}); | |||||||||||||||||||||||||||
| 46 | 0 | $self->grab; | |||||||||||||||||||||||||||
| 47 | 0 | return $self; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 50 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 51 | ### GrabServer-object DESTROY() | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | $self->ungrab; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # ### initial error: $@ | ||||||||||||||||||||||||||||
| 56 | # local $@; # don't clobber if destroyed during a die() unwind | ||||||||||||||||||||||||||||
| 57 | # eval { $self->ungrab }; # ignore EPIPE write if server already closed | ||||||||||||||||||||||||||||
| 58 | # ### DESTROY error: $@ | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub grab { | ||||||||||||||||||||||||||
|
Subroutine
grab: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 63 | ### GrabServer-object grab() | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | unless ($self->{'grabbed'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $X = $self->{'X'} || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'X'} || (return)
MC/DC0%0/1
$self->{'X'} || (return)
$self->{'X'}
Truth table0%0/2
A
A= $self->{'X'}
| |||||||||||||||||||||||||||||
| 66 | 0 | $self->{'grabbed'} = 1; | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | if (! $X->{__PACKAGE__.'.count'}++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | ### initial X->GrabServer | ||||||||||||||||||||||||||||
| 69 | 0 | $X->GrabServer; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | ### grab count now: $self->{'X'} && $self->{'X'}->{__PACKAGE__.'.count'} | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub ungrab { | ||||||||||||||||||||||||||
|
Subroutine
ungrab: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 77 | ### GrabServer-object ungrab() | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if (delete $self->{'grabbed'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my $X = $self->{'X'} || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'X'} || (return)
MC/DC0%0/1
$self->{'X'} || (return)
$self->{'X'}
Truth table0%0/2
A
A= $self->{'X'}
| |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if (--$X->{__PACKAGE__.'.count'} <= 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | delete $X->{__PACKAGE__.'.count'}; # cleanup | |||||||||||||||||||||||||||
| 82 | ### final X->UngrabServer | ||||||||||||||||||||||||||||
| 83 | 0 | $X->UngrabServer; | |||||||||||||||||||||||||||
| 84 | 0 | $X->flush; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | ### grab count now: $self->{'X'} && $self->{'X'}->{__PACKAGE__.'.count'} | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub is_grabbed { | ||||||||||||||||||||||||||
|
Subroutine
is_grabbed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 92 | 0 | return $self->{'grabbed'}; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # # not sure about this ... | ||||||||||||||||||||||||||||
| 96 | # sub call_with_grab { | ||||||||||||||||||||||||||||
| 97 | # my $class = shift; | ||||||||||||||||||||||||||||
| 98 | # my $X = shift; | ||||||||||||||||||||||||||||
| 99 | # my $subr = shift; | ||||||||||||||||||||||||||||
| 100 | # my $grab = $class->new ($X); | ||||||||||||||||||||||||||||
| 101 | # &$subr (@_); | ||||||||||||||||||||||||||||
| 102 | # } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1 | 1; | |||||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||||||