
[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
RE: [ic] mv_credit_card_reference
Mike Heins said:
> I am working on a new programming guide, and one of the first things
> it says is:
>
> Don't use GlobalSub.
>
> The real method of doing this is just change your GlobalSub to a
> $Tag, i.e. a global UserTag. Perhaps I should make a $Sub object...8-)
>
> All you need to do is:
>
> GlobalSub <<EOR
> sub somesub {
> # some code
> }
> EOR
>
> Change that to:
>
> UserTag somesub Order something
> UserTag somesub Routine <<EOR
> sub {
> # same code
> }
> EOR
>
> Then call it with $Tag->somesub($something);
>
> It is usually nice to put an option hash at the end:
>
> UserTag somesub addAttr
>
> That way you can pass additional params without having to
> preposition the arguments:
>
> UserTag somesub Order something
> UserTag somesub addAttr
> UserTag somesub Routine <<EOR
> sub {
> my ($something, $opt) = @_;
> $opt ||= {};
>
> if($opt->{this}) {
> that();
> }
> # some code
> }
> EOR
Ok, lesson learned... I've changed my GlobalSubs to UserTags, but I am STILL
having problems :) While I've successfully created an MD5 calculator tag, I
have another one which tries to post a form to a given URL. This is very
similar to the get_url tag in the usertag/ directory, but I need the POST
method not GET, and I would like to obtain the HTTP code and message to
check for errors too. I call this tag web-service:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
UserTag web-service Order url code message
UserTag web-service addAttr
UserTag web-service Documentation <<EOD
usage: $Tag->web_service($url, $code, $message, $params)
EOD
UserTag web-service Routine <<EOR
sub {
my ($url, $code, $message, $data) = @_;
eval {
require LWP::UserAgent;
require HTTP::Request::Common;
};
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request::Common::POST $url, $data;
my $response = $ua->request($req);
$code = $response->code;
$message = $response->message;
return $response->content;
}
EOR
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
As I'm using some of the tag parameters to return data, I think this tag is
little suitable for the ITL syntax [web-service url="..." etc.], but this
poses no problem for me because I'm going to call it from [perl] through the
$Tag hash.
If I put a call in a blank page, for example
>>>>>>>>>>>>
[perl] $Tag->web_service("www.google.com/search",
$code,
$msg,
{ 'q' => 'search something for me' })
[/perl]
>>>>>>>>>>>>>>
Then, what I get is:
"Safe: require trapped by operation mask at (eval 256) line 3."
I think the 'line 3' refers to some piece of code deep inside the guts of
the HTTP::Request::Common::POST subroutine, because the trap occurs there.
But... Am I not supposed to be able to do whatever I want from a global
UserTag routine? I'm confused.
BTW, my versions are:
perl 5.6.0
ic 4.8.2
Safe 2.06
HTTP::Request::Common 1.19
Javier
_______________________________________________
interchange-users mailing list
interchange-users@interchange.redhat.com
http://interchange.redhat.com/mailman/listinfo/interchange-users