[interchange-cvs] interchange - racke modified code/UserTag/get_url.tag

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Tue Dec 4 19:38:04 EST 2007


User:      racke
Date:      2007-12-05 00:38:04 GMT
Modified:  code/UserTag get_url.tag
Log:
replace pathetic regex usage with simple code

Revision  Changes    Path
1.12      +15 -17    interchange/code/UserTag/get_url.tag


rev 1.12, prev_rev 1.11
Index: get_url.tag
===================================================================
RCS file: /var/cvs/interchange/code/UserTag/get_url.tag,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- get_url.tag	2 Nov 2007 20:26:00 -0000	1.11
+++ get_url.tag	5 Dec 2007 00:38:03 -0000	1.12
@@ -5,30 +5,26 @@
 # the Free Software Foundation; either version 2 of the License, or
 # (at your option) any later version.  See the LICENSE file for details.
 # 
-# $Id: get_url.tag,v 1.11 2007/11/02 20:26:00 racke Exp $
+# $Id: get_url.tag,v 1.12 2007/12/05 00:38:03 racke Exp $
 
 UserTag get-url Order        url
 UserTag get-url AddAttr
 UserTag get-url Interpolate
-UserTag get-url Version      $Revision: 1.11 $
+UserTag get-url Version      $Revision: 1.12 $
 UserTag get-url Routine      <<EOR
 require LWP::UserAgent;
 sub {
 	my ($url, $opt) = @_;
 	my $html = '';
+	my $method;
 	
 	my $ua = LWP::UserAgent->new;
 
-	my $method = '';
 	if($opt->{method}) { 
-		$method = $opt->{method}; 
-		if("GET HEAD POST PUT" !~ /$method/) {
-			$method = "GET";
-		}
+		$method = uc($opt->{method});
+	} else {
+		$method = 'GET';
 	}
-	else { $method = "GET"; }
-
-	$method = uc $method;
 
     if($opt->{timeout}) {
 		my $to = Vend::Config::time_to_seconds($opt->{timeout});
@@ -45,13 +41,15 @@
 
 	my $do_content;
 
-	if(($opt->{content}) && ("PUT POST" =~ /$method/)) { 
-		$opt->{content_type} ||= 'application/x-www-form-urlencoded';
-		$do_content = 1;
-	}
-	elsif($opt->{content}) {
-		$url .= $opt->{url} =~ /\?/ ? '&' : '?';
-		$url .= $opt->{content};
+	if ($opt->{content}) {
+		if ($method eq 'POST' || $method eq 'PUT') {
+			$opt->{content_type} ||= 'application/x-www-form-urlencoded';
+			$do_content = 1;
+		} 
+		else {
+			$url .= $opt->{url} =~ /\?/ ? '&' : '?';
+			$url .= $opt->{content};
+		}
 	}
 
 	my $req = HTTP::Request->new($method, $url);








More information about the interchange-cvs mailing list