SVN: toys/rsget.pl/RSGet: Curl.pm Hook.pm

sparky sparky at pld-linux.org
Wed Jul 28 15:19:42 CEST 2010


Author: sparky
Date: Wed Jul 28 15:19:41 2010
New Revision: 11718

Added:
   toys/rsget.pl/RSGet/Hook.pm   (contents, props changed)
Modified:
   toys/rsget.pl/RSGet/Curl.pm
Log:
- moved callback code from RSGet::Curl to its own place


Modified: toys/rsget.pl/RSGet/Curl.pm
==============================================================================
--- toys/rsget.pl/RSGet/Curl.pm	(original)
+++ toys/rsget.pl/RSGet/Curl.pm	Wed Jul 28 15:19:41 2010
@@ -9,6 +9,7 @@
 use warnings;
 use RSGet::Tools;
 use RSGet::Line;
+use RSGet::Hook;
 use WWW::Curl::Easy 4.00;
 use WWW::Curl::Multi;
 use URI::Escape;
@@ -534,7 +535,7 @@
 			bignum( $supercurl->{size_total} );
 
 		if ( my $post = setting( "postdownload" ) ) {
-			callback( $post,
+			RSGet::Hook::call( $post,
 				file => $outfile,
 				name => $supercurl->{fname},
 				size => $supercurl->{size_total},
@@ -660,35 +661,6 @@
 	return bignum( $supercurl->{size_got} ) . "; ${speed}KB/s $eta";
 }
 
-sub shquote
-{
-	local $_ = shift;
-	s/'/'"'"'/g;
-	return "'$_'";
-}
-
-sub callback
-{
-	my $hook = shift;
-	my %opts = @_;
-
-	$hook =~ s/(\$\(([a-z]*)\))/shquote( $opts{ $2 } || $1 )/eg;
-
-	my $pid = fork;
-	unless ( defined $pid ) {
-		warn "Fork failed\n";
-	}
-	if ( $pid ) {
-		p "Executing '$hook'\n" if verbose( 1 );
-	} else {
-		close STDIN;
-		close STDOUT;
-		close STDERR;
-		exec $hook;
-		die "Exec failed: $@\n";
-	}
-}
-
 
 1;
 

Added: toys/rsget.pl/RSGet/Hook.pm
==============================================================================
--- (empty file)
+++ toys/rsget.pl/RSGet/Hook.pm	Wed Jul 28 15:19:41 2010
@@ -0,0 +1,46 @@
+package RSGet::Hook;
+# This file is an integral part of rsget.pl downloader.
+#
+# 2010 (c) Przemysław Iskra <sparky at pld-linux.org>
+#		This program is free software,
+# you may distribute it under GPL v2 or newer.
+
+use strict;
+use warnings;
+use RSGet::Tools;
+use RSGet::Line;
+set_rev qq$Id$;
+
+sub shquote
+{
+	local $_ = shift;
+	s/'/'"'"'/g;
+	return "'$_'";
+}
+
+sub call
+{
+	my $hook = shift;
+	my %opts = @_;
+
+	$hook =~ s/(\$\(([a-z]*)\))/shquote( $opts{ $2 } || $1 )/eg;
+
+	my $pid = fork;
+	unless ( defined $pid ) {
+		warn "Fork failed\n";
+	}
+	if ( $pid ) {
+		p "Executing '$hook'\n" if verbose( 1 );
+	} else {
+		close STDIN;
+		close STDOUT;
+		close STDERR;
+		exec $hook;
+		die "Exec failed: $@\n";
+	}
+}
+
+
+1;
+
+# vim: ts=4:sw=4


More information about the pld-cvs-commit mailing list