From 15df13f90cb03e39db71a95b24896a2f0485bffd Mon Sep 17 00:00:00 2001 From: Slaven Rezic Date: Wed, 5 Aug 2015 23:27:47 +0200 Subject: [PATCH] more maybe_mount improvements Change return type of callback: now it's a hashref instead of a hash, so the callback can simply return nothing (which is: undef) without causing any "Odd number of elements in hash assignment" warnings. Document maybe_mount() usage. --- GPS/BBBikeGPS/MountedDevice.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/GPS/BBBikeGPS/MountedDevice.pm b/GPS/BBBikeGPS/MountedDevice.pm index 7955c746ca..ef23523e23 100644 --- a/GPS/BBBikeGPS/MountedDevice.pm +++ b/GPS/BBBikeGPS/MountedDevice.pm @@ -78,13 +78,21 @@ unlink $ofile; # as soon as possible - (files => [$dest]); + +{ files => [$dest] }; }); } sub transfer { } # NOP + # maybe_mount() may also be called outside of the Perl/Tk + # application for scripts which have to copy from or to the + # mounted gps device. Simple usage example: + # + # perl -w -Ilib -MGPS::BBBikeGPS::MountedDevice -e 'GPS::BBBikeGPS::MountedDevice->maybe_mount(sub { my $dir = shift; system("ls -al $dir"); 1 })' + # + # Currently only the internal flash card is supported, but in + # future this can be controlled with options. sub maybe_mount { my(undef, $cb, %opts) = @_; @@ -171,7 +179,7 @@ ###################################################################### # call the callback - my %info = $cb->($mount_point); + my $info = $cb->($mount_point); ###################################################################### # do the unmount (maybe) @@ -186,8 +194,8 @@ } } else { # Make sure generated file(s) are really written if possible - if ($info{files}) { - my @sync_files = @{ $info{files} || [] }; + if (ref $info eq 'HASH' && $info->{files}) { + my @sync_files = @{ $info->{files} || [] }; if (eval { require File::Sync; 1 }) { for my $sync_file (@sync_files) { if (open my $fh, $sync_file) {