lib/Clipboard/Xclip.pm

filter: Statementstmt 38.1% 21 / 55 Branchbran 8.3% 1 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 36.3% 4 / 11 Podpod 0.0% 0 / 8 totaltotal 30.2% 26 / 86 CC 8 SCAR 19.8
CC
8
Cov
33%
copy_to_selection
12.0
paste
12.0
paste_from_selection
12.0
CRAP 7.2
« lib/Clipboard.pm ↑ Summary blib/lib/Clipboard/WaylandClipboard.pm »
1 package Clipboard::Xclip;
2 2 $Clipboard::Xclip::VERSION = '0.32';
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶sub copy {
Subroutine copy: not called CC=1 SCAR=6.9
Pod undocumented
9 0 my $self = shift;
10 0 my ($input) = @_;
11 0 return $self->copy_to_selection($self->favorite_selection, $input);
12 }
13  
14 0 ▶sub copy_to_all_selections {
Subroutine copy_to_all_selections: not called CC=2 SCAR=17.9
Pod undocumented
15 0 my $self = shift;
16 0 my ($input) = @_;
17 0 foreach my $sel ($self->all_selections) {
18 0 $self->copy_to_selection($sel, $input);
19 }
20 0 return;
21 }
22  
23 0 ▶sub copy_to_selection {
Subroutine copy_to_selection: not called CC=3 SCAR=24.8
Pod undocumented
24 0 my $self = shift;
25 0 my ($selection, $input) = @_;
26 0 my $cmd = '|xclip -i -selection '. $selection;
27 0 ▶ my $r = open my $exe, $cmd or die "Couldn't run `$cmd`: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
my $r = open(my $exe, $cmd) or die "Couldn't run `$cmd`: $!\n" 0 0 0
28 0 binmode $exe, ':encoding(UTF-8)';
29 0 print {$exe} $input;
30 0 ▶ close $exe or die "Error closing `$cmd`: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $exe or die "Error closing `$cmd`: $!" 0 0 0
31  
32 0 return;
33 }
34 0 ▶sub paste {
Subroutine paste: not called CC=3 SCAR=24.8
Pod undocumented
35 0 my $self = shift;
36 0 for ($self->all_selections) {
37 0 my $data = $self->paste_from_selection($_);
38 0 ▶ return $data if length $data;
Branch: 1 branch
BranchTrueFalseTotal
if length $data 0 0 0
39 }
40 0 return undef;
41 }
42 0 ▶sub paste_from_selection {
Subroutine paste_from_selection: not called CC=3 SCAR=24.8
Pod undocumented
43 0 my $self = shift;
44 0 my ($selection) = @_;
45 0 my $cmd = "xclip -o -selection $selection|";
46 0 ▶ open my $exe, $cmd or die "Couldn't run `$cmd`: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $exe, $cmd or die "Couldn't run `$cmd`: $!\n" 0 0 0
47 0 my $result = do { local $/; <$exe> };
48 0 ▶ close $exe or die "Error closing `$cmd`: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $exe or die "Error closing `$cmd`: $!" 0 0 0
49 0 return $result;
50 }
51 # This ordering isn't officially verified, but so far seems to work the best:
52 0 ▶sub all_selections { qw(primary buffer clipboard secondary) }
Subroutine all_selections: not called CC=1 SCAR=6.9
Pod undocumented
53 0 ▶sub favorite_selection { my $self = shift; ($self->all_selections)[0] }
Subroutine favorite_selection: not called CC=1 SCAR=6.9
Pod undocumented
54  
55 2 ▶sub xclip_available {
Subroutine xclip_available: called CC=1 SCAR=0.0
Pod undocumented
56 # close STDERR
57 2 open my $olderr, '>&', \*STDERR;
58 2 close STDERR;
59 2 open STDERR, '>', File::Spec->devnull;
60  
61 2 my $open_retval = open my $just_checking, 'xclip -o|';
62  
63 # restore STDERR
64 2 close STDERR;
65 2 open STDERR, '>&', $olderr;
66 2 close $olderr;
67  
68 2 return $open_retval;
69 }
70  
71 {
72 2 ▶ xclip_available() or warn <<'EPIGRAPH';
Branch: 1 branch
BranchTrueFalseTotal
xclip_available() or warn "\nCan't find the 'xclip' program. Clipboard.pm's X support depends on it.\n\nHere's the project homepage: http://sourceforge.net/projects/xclip/\n\n" 0 2 2
73  
74 Can't find the 'xclip' program. Clipboard.pm's X support depends on it.
75  
76 Here's the project homepage: http://sourceforge.net/projects/xclip/
77  
78 EPIGRAPH
79 }
80  
81 2 1;
82  
83 __END__
« lib/Clipboard.pm ↑ Summary blib/lib/Clipboard/WaylandClipboard.pm »