From a22ee15c603e3fb7066fdd2eca8adf192719ca97 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 10 Jul 2011 10:57:32 +0200 Subject: Raps2/UI.pm: to_clipboard: Return undef if xclip fails --- lib/App/Raps2/UI.pm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/App/Raps2/UI.pm b/lib/App/Raps2/UI.pm index d993316..2392ec6 100644 --- a/lib/App/Raps2/UI.pm +++ b/lib/App/Raps2/UI.pm @@ -4,7 +4,7 @@ use strict; use warnings; use 5.010; -use Carp qw(confess); +use Carp qw(cluck confess); use POSIX; use Term::ReadLine; @@ -31,7 +31,7 @@ sub list { } printf( $format, map { $_->[1] // q{} } @list ); - return; + return 1; } sub read_line { @@ -92,14 +92,14 @@ sub to_clipboard { my ( $self, $str ) = @_; open( my $clipboard, q{|-}, 'xclip -l 1' ) - or confess("Failed to execute xclip -l 1: $!"); + or return; print $clipboard $str; close($clipboard) - or confess("Failed to close pipe to xclip: $!"); + or cluck("Failed to close pipe to xclip: $!"); - return; + return 1; } sub output { @@ -109,7 +109,7 @@ sub output { printf( "%-8s : %s\n", $pair->[0], $pair->[1] // q{}, ); } - return; + return 1; } 1; @@ -174,7 +174,10 @@ otherwise B dies. Returns the input. =item $ui->to_clipboard(I<$string>) -Place I in the primary X Clipboard. +Place I in the primary X Clipboard (by calling the B program) + +Returns true upon success, undef if the operation failed. Use $! to get the +error message. =item $ui->output(I<\@pair>, I<...>) -- cgit v1.2.3