Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Interchange: users

usertag passing args by reference (perl newby)

 

 

Interchange users RSS feed   Index | Next | Previous | View Threaded


m.mescoli at omnib

Aug 27, 2008, 12:06 AM

Post #1 of 11 (583 views)
Permalink
usertag passing args by reference (perl newby)

Dear list
Is there an example to pass args to a usertag for reference or have more
then one return value from a usertag?

Thanks to all
Marco Mescoli

_______________________________________________
interchange-users mailing list
interchange-users[at]icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users


gert at 3edge

Aug 27, 2008, 1:30 AM

Post #2 of 11 (571 views)
Permalink
Re: usertag passing args by reference (perl newby) [In reply to]

> -----Original Message-----
> From: interchange-users-bounces[at]icdevgroup.org [mailto:interchange-
> users-bounces[at]icdevgroup.org] On Behalf Of Marco Mescoli
> Sent: woensdag 27 augustus 2008 10:07
> To: interchange-users[at]icdevgroup.org
> Subject: [ic] usertag passing args by reference (perl newby)
>
> Dear list
> Is there an example to pass args to a usertag for reference or have
> more
> then one return value from a usertag?

In code/UI_Tag/list_pages.coretag you have a usertag which returns either
an array reference, or a string value

\@pages is a reference to an array, so it can contain multiple values.
You can also return a reference to a hash for example ...

Here a standard perl example for passing on arrayreferences:
http://icfun.blogspot.com/2008/06/perl-returning-array-reference-from.html

For passing arguments to a usertag, I suggest you read:
http://www.interchange.rtfm.info/icdocs/Creating_custom_Interchange_tags.htm
l


CU,

Gert


_______________________________________________
interchange-users mailing list
interchange-users[at]icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users


racke at linuxia

Aug 27, 2008, 1:33 AM

Post #3 of 11 (571 views)
Permalink
Re: usertag passing args by reference (perl newby) [In reply to]

Marco Mescoli wrote:
> Dear list
> Is there an example to pass args to a usertag for reference or have more
> then one return value from a usertag?

Inside of embedded Perl / UserTags you can pass references back and forth
to Usertags.

In ITL you can do things like:

[calc] $Scratch->{example} = {foo => 'bar', duh => 'xxx'}; return; [/calc]

[mytag myarg=`$Scratch->{example}`]

You can also return something different from a usertag depending on the
caller:

if (wantarray()) {
return @path;
} else {
$joiner = $opt->{joiner} || ' ';
return join($joiner, @path);
}

If this tag is called from ITL, it will return the string.
If this tag is called from Perl/UserTag it depends on the context.

Regards
Racke


--
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team


_______________________________________________
interchange-users mailing list
interchange-users[at]icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users


m.mescoli at omnib

Aug 27, 2008, 2:11 AM

Post #4 of 11 (566 views)
Permalink
Re: usertag passing args by reference (perl newby) [In reply to]

perl calc foo bar scratch scratch scratch :-O
... i must study

Thanks to all
Marco

_______________________________________________
interchange-users mailing list
interchange-users[at]icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users


m.mescoli at omnib

Aug 27, 2008, 3:11 AM

Post #5 of 11 (566 views)
Permalink
Re: usertag passing args by reference (perl newby) [In reply to]

And if i want to pass the address of a scratch var and modify the var
inside mytag ?
Something like this:

-------- mytag.tag ------------
UserTag mytag Order myarg
UserTag mytag Routine <<EOR
sub {
my $ref = shift;
$($ref) = 'bar'; # :-?
return;
}
EOR

--------- mytest.html --------
[set example]foo[/set]
[scratch example]
[mytag myarg=`\$Scratch->{example}`]
<br />[scratch example]

---------- output -----------
foo
bar


Marco

_______________________________________________
interchange-users mailing list
interchange-users[at]icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users


racke at linuxia

Aug 27, 2008, 3:16 AM

Post #6 of 11 (566 views)
Permalink
Re: usertag passing args by reference (perl newby) [In reply to]

Marco Mescoli wrote:
> And if i want to pass the address of a scratch var and modify the var
> inside mytag ?

Just pass the name of the scratch variable and use $Scratch to manipulate
it.

> Something like this:
>
> -------- mytag.tag ------------
> UserTag mytag Order myarg
> UserTag mytag Routine <<EOR
> sub {
> my $ref = shift;
> $($ref) = 'bar'; # :-?
> return;
> }
> EOR

UserTag mytag Order myarg
UserTag mytag Routine <<EOR
sub {
my $ref = shift;

$Scratch->{$arg} = 'bar';
return;
}

Regards
Racke


--
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team


_______________________________________________
interchange-users mailing list
interchange-users[at]icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users


gert at 3edge

Aug 27, 2008, 3:21 AM

Post #7 of 11 (566 views)
Permalink
Re: usertag passing args by reference (perl newby) [In reply to]

> -----Original Message-----
> From: interchange-users-bounces[at]icdevgroup.org [mailto:interchange-
> users-bounces[at]icdevgroup.org] On Behalf Of Stefan Hornburg
> Sent: woensdag 27 augustus 2008 13:17
> To: interchange-users[at]icdevgroup.org
> Subject: Re: [ic] usertag passing args by reference (perl newby)
>
> Marco Mescoli wrote:
> > And if i want to pass the address of a scratch var and modify the var
> > inside mytag ?
>
> Just pass the name of the scratch variable and use $Scratch to
> manipulate
> it.
>
> > Something like this:
> >
> > -------- mytag.tag ------------
> > UserTag mytag Order myarg
> > UserTag mytag Routine <<EOR
> > sub {
> > my $ref = shift;
> > $($ref) = 'bar'; # :-?
> > return;
> > }
> > EOR
>
> UserTag mytag Order myarg
> UserTag mytag Routine <<EOR
> sub {
> my $ref = shift;
>
> $Scratch->{$arg} = 'bar';
> return;
> }
>
> Regards
> Racke

Then probably not $arg in the {} as it sets my $ref ... But that's the basic
idea yes :)

You could also probably do [seti myexample][mytag ... ][/seti] ...

But if you are trying to do something specific/fancy ... Sometimes it is
best to explain what you really want to achieve.
The solution might not lie with the passing the arguments to a usertag etc
...

CU,

Gert








_______________________________________________
interchange-users mailing list
interchange-users[at]icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users


m.mescoli at omnib

Aug 27, 2008, 3:32 AM

Post #8 of 11 (567 views)
Permalink
Re: usertag passing args by reference (perl newby) [In reply to]

Simple and clear.

Thanks
Marco

Stefan Hornburg wrote:
> Marco Mescoli wrote:
>
>>And if i want to pass the address of a scratch var and modify the var
>>inside mytag ?
>
> Just pass the name of the scratch variable and use $Scratch to manipulate
> it.

_______________________________________________
interchange-users mailing list
interchange-users[at]icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users


m.mescoli at omnib

Aug 27, 2008, 4:18 AM

Post #9 of 11 (563 views)
Permalink
Re: usertag passing args by reference (perl newby) [In reply to]

I am working to a usertag to calculate day worktime beetwen more time
marks (manual clock mark, sms mark, web mark). If i cannot find correct
sequence entry-exit i must return the partial time computed and the code
error (no entry, no exit .... ). Passing to the usertag the name of a
scratch var to get the error is a simple good way to handle the problem.
Sorry and thanks for the other suggestion that going (slow ;-) me to
perl computing often more simple than i think.

Marco

Gert van der Spoel wrote:
>>-----Original Message-----
>>From: interchange-users-bounces[at]icdevgroup.org [mailto:interchange-
>>users-bounces[at]icdevgroup.org] On Behalf Of Stefan Hornburg
>>Sent: woensdag 27 augustus 2008 13:17
>>To: interchange-users[at]icdevgroup.org
>>Subject: Re: [ic] usertag passing args by reference (perl newby)
>>
>>Marco Mescoli wrote:
>>
>>>And if i want to pass the address of a scratch var and modify the var
>>>inside mytag ?
>>
>>Just pass the name of the scratch variable and use $Scratch to
>>manipulate
>>it.
>>
>>
>>>Something like this:
>>>
>>>-------- mytag.tag ------------
>>>UserTag mytag Order myarg
>>>UserTag mytag Routine <<EOR
>>>sub {
>>> my $ref = shift;
>>> $($ref) = 'bar'; # :-?
>>> return;
>>>}
>>>EOR
>>
>>UserTag mytag Order myarg
>>UserTag mytag Routine <<EOR
>>sub {
>> my $ref = shift;
>>
>> $Scratch->{$arg} = 'bar';
>> return;
>>}
>>
>>Regards
>> Racke
>
>
> Then probably not $arg in the {} as it sets my $ref ... But that's the basic
> idea yes :)
>
> You could also probably do [seti myexample][mytag ... ][/seti] ...
>
> But if you are trying to do something specific/fancy ... Sometimes it is
> best to explain what you really want to achieve.
> The solution might not lie with the passing the arguments to a usertag etc
> ...
>
> CU,
>
> Gert

_______________________________________________
interchange-users mailing list
interchange-users[at]icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users


racke at linuxia

Aug 27, 2008, 4:40 AM

Post #10 of 11 (563 views)
Permalink
Re: usertag passing args by reference (perl newby) [In reply to]

Marco Mescoli wrote:
> I am working to a usertag to calculate day worktime beetwen more time
> marks (manual clock mark, sms mark, web mark). If i cannot find correct
> sequence entry-exit i must return the partial time computed and the code
> error (no entry, no exit .... ). Passing to the usertag the name of a
> scratch var to get the error is a simple good way to handle the problem.
> Sorry and thanks for the other suggestion that going (slow ;-) me to
> perl computing often more simple than i think.

Did you take a look at the modules provided by datetime.perl.org? I based
some custom code for calendaring and dispatch calculation on them, with
[datetime] and [crontime] usertags. These allow me to pass DateTime objects
and relatives between usertags and Perl code back and forth.

Regards
Racke


--
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team


_______________________________________________
interchange-users mailing list
interchange-users[at]icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users


m.mescoli at omnib

Aug 27, 2008, 5:16 AM

Post #11 of 11 (563 views)
Permalink
Re: usertag passing args by reference (perl newby) [In reply to]

Good suggestion. Now inside usertag i use HTTP::Date computing with
seconds (str2time) and returning sprintf string like 'hh:mm' with
calculation of hours an minutes.

Marco

Stefan Hornburg wrote:
> Marco Mescoli wrote:
>
>>I am working to a usertag to calculate day worktime beetwen more time
>>marks (manual clock mark, sms mark, web mark). If i cannot find correct
>>sequence entry-exit i must return the partial time computed and the code
>>error (no entry, no exit .... ). Passing to the usertag the name of a
>>scratch var to get the error is a simple good way to handle the problem.
>>Sorry and thanks for the other suggestion that going (slow ;-) me to
>>perl computing often more simple than i think.
>
>
> Did you take a look at the modules provided by datetime.perl.org? I based
> some custom code for calendaring and dispatch calculation on them, with
> [datetime] and [crontime] usertags. These allow me to pass DateTime objects
> and relatives between usertags and Perl code back and forth.
>
> Regards
> Racke
>
>

_______________________________________________
interchange-users mailing list
interchange-users[at]icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users

Interchange users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.