diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-07-10 10:57:32 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-07-10 10:57:32 +0200 |
commit | a22ee15c603e3fb7066fdd2eca8adf192719ca97 (patch) | |
tree | cc50546af47cbb156309c9c0caca831e702bf493 | |
parent | 622a4ad3f3e7da1837f253f816788069631891ad (diff) |
Raps2/UI.pm: to_clipboard: Return undef if xclip fails
-rw-r--r-- | Changelog | 3 | ||||
-rwxr-xr-x | bin/raps2 | 3 | ||||
-rw-r--r-- | lib/App/Raps2/UI.pm | 17 |
3 files changed, 15 insertions, 8 deletions
@@ -2,6 +2,9 @@ git HEAD * Major usability improvements + [App::Raps2::UI] + * to_clipboard: Return undef if xclip dosn't run, true otherwise + App::Raps2 0.50 - Fri Jul 08 2011 * Switch to perl version scheme @@ -146,7 +146,8 @@ sub cmd_get { my $key = $raps2->pw_load( file => $pwfile ); - $raps2->ui->to_clipboard( $key->{password} ); + $raps2->ui->to_clipboard( $key->{password} ) + or die("Could not place password in clipboard: ${!}\n"); if ( $key->{extra} ) { print $key->{extra}; 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<read_pw> dies. Returns the input. =item $ui->to_clipboard(I<$string>) -Place I<string> in the primary X Clipboard. +Place I<string> in the primary X Clipboard (by calling the B<xclip> program) + +Returns true upon success, undef if the operation failed. Use $! to get the +error message. =item $ui->output(I<\@pair>, I<...>) |