Re: alternative to feature 'signatures'?

2018-02-26 Thread hw
Илья Рассадин  writes:

> Why can't you use 'signatures' feature at the first place?

The perl version I am required to use does not support it.

> Usually, it means that you tight yourself to system perl, which is not
> a good decision at all.
>
> Don't trust me on this, trust brian d foy
> https://www.effectiveperlprogramming.com/2015/11/apple-recommends-installing-your-own-perl/
>
> Install different perl version is quite a trivial task, especially
> with tools like perlbrew and plenv.
>
> Next, You can easily install modules you need via cpanm or carton.

I have tried to use a more recent version of perl which has feature
'signatures' on Centos 7 without success.

It is basically possible to use more recent versions of perl, but it
doesn´t seem possible to bring lighttpd to use such versions.  It
insists on not loading the libraries required by more recent versions of
perl.  And I can not get around running the perl programs as CGI.

When I encountered this problem, I tought it´s easy enough to modify the
programs, but it turns out that this feature is virtually a
requirement.  Without it, I will have to go to ridiculous lengths to
simulate what it does, which is error prone and costs performance.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: alternative to feature 'signatures'?

2017-12-14 Thread Илья Рассадин

Why can't you use 'signatures' feature at the first place?

Usually, it means that you tight yourself to system perl, which is not a 
good decision at all.


Don't trust me on this, trust brian d foy 
https://www.effectiveperlprogramming.com/2015/11/apple-recommends-installing-your-own-perl/


Install different perl version is quite a trivial task, especially with 
tools like perlbrew and plenv.


Next, You can easily install modules you need via cpanm or carton.

10.12.2017 18:18, hw пишет:

hw  writes:


Gil Magno  writes:


On 19/11/17 13:57, hw wrote:

without being able to use feature 'signatures', how do I verify
that parameters passed to a function have been passed to it by
the caller?

https://metacpan.org/pod/signatures
https://metacpan.org/pod/signatures#SEE-ALSO

https://metacpan.org/pod/Sub::Signatures

You can search for 'signatures' on CPAN in order to find other modules
alike.

Ah, yes I should have thought of that, thanks!  There´s even a package
'perl-Parse-Method-Signatures.noarch' in Centos; I´ll look into that.

Well, so I looked and found it isn´t for what I´d need it for.

Is there really no good alternative to signatures?



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: alternative to feature 'signatures'?

2017-12-14 Thread hw
hw  writes:

> Gil Magno  writes:
>
>> On 19/11/17 13:57, hw wrote:
>>> without being able to use feature 'signatures', how do I verify
>>> that parameters passed to a function have been passed to it by
>>> the caller?
>>
>> https://metacpan.org/pod/signatures
>> https://metacpan.org/pod/signatures#SEE-ALSO
>>
>> https://metacpan.org/pod/Sub::Signatures
>>
>> You can search for 'signatures' on CPAN in order to find other modules
>> alike.
>
> Ah, yes I should have thought of that, thanks!  There´s even a package
> 'perl-Parse-Method-Signatures.noarch' in Centos; I´ll look into that.

Well, so I looked and found it isn´t for what I´d need it for.

Is there really no good alternative to signatures?

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: alternative to feature 'signatures'?

2017-11-28 Thread hw
Gil Magno  writes:

> On 19/11/17 13:57, hw wrote:
>> without being able to use feature 'signatures', how do I verify
>> that parameters passed to a function have been passed to it by
>> the caller?
>
> https://metacpan.org/pod/signatures
> https://metacpan.org/pod/signatures#SEE-ALSO
>
> https://metacpan.org/pod/Sub::Signatures
>
> You can search for 'signatures' on CPAN in order to find other modules
> alike.

Ah, yes I should have thought of that, thanks!  There´s even a package
'perl-Parse-Method-Signatures.noarch' in Centos; I´ll look into that.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: alternative to feature 'signatures'?

2017-11-22 Thread Gil Magno
On 19/11/17 13:57, hw wrote:
> without being able to use feature 'signatures', how do I verify
> that parameters passed to a function have been passed to it by
> the caller?

https://metacpan.org/pod/signatures
https://metacpan.org/pod/signatures#SEE-ALSO

https://metacpan.org/pod/Sub::Signatures

You can search for 'signatures' on CPAN in order to find other modules
alike.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: alternative to feature 'signatures'?

2017-11-22 Thread hw

Chas. Owens wrote:

What no one has said so far is the importance of using Carp when throwing 
errors related to how the function was called.  The Carp module provides 
versions of warn (carp) and die (croak) that give the line and file where the 
call to the function occurred rather than the line of the carp or croak:


Unfortunately, having the carps displayed to the user when using CGI
doesn´t always work ...

And I still need to have the arguments verified by obsolete code before
carp could step in ...

It´s amazing that such a very basic feature as 'signatures' is still
experimental.  Why wasn´t it implemented right away when functions were,
as it should have?  We´re really being left hanging in a void here.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: alternative to feature 'signatures'?

2017-11-22 Thread hw

Gil Magno wrote:

On 19/11/17 13:57, hw wrote:

without being able to use feature 'signatures', how do I verify
that parameters passed to a function have been passed to it by
the caller?


If you're dealing with positional parameters[1] (and not with named
ones) you can check for the size of @_ inside your function, that is,
you can check for the quantity of parameters given by the caller.

sub one {
$num_of_params = scalar @_;
print "$num_of_params\n";
}

one('str1'); # prints '1'; there's just one parameter

one('str2', undef); # prints '2'; the second parameter is undef,
# but the undef counts and it prints '2'

[1] Positional parameters would be as in sub_one('John', 'Zimbabwe');
and named parameters as in sub_two({ name => 'John', country =>
'Zimbabwe' });



I´m dealing with both types.

I shouldn´t even need to explicitly verify if positional arguments
required by a function have been supplied to it.  It´s enough having to
verify that the values which were supplied via such arguments are ok, and
verifying the arguments themselves means having to add basically obsolete
code.

Isn´t there some sort of perl interpreter/compiler/module which can verify
the passing of arguments automatically at least when running the program in
some sort of debugging mode?

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: alternative to feature 'signatures'?

2017-11-22 Thread hw

Andrew Solomon wrote:

This is how I'd go about it:

https://gist.github.com/andrewsolomon/323a2b317ea5903f662fbaaded254798

"exists" is true if there's a key in a hash even if the key's value is undef.

Does that provide a solution for you, or are there other constraints?


That would require to put the arguments of lots of functions into hashes.

I´m looking for something simple and preferably (mostly) automatic which
doesn´t require to make a lot of changes, like using hashes or counting
the number of arguments would.

Feature 'signatures' would be great, but the perl version in Centos is
too old to have it, and I couldn´t figure out how to use a more recent
version with lighttpd.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: alternative to feature 'signatures'?

2017-11-19 Thread Chas. Owens
What no one has said so far is the importance of using Carp when throwing
errors related to how the function was called.  The Carp module provides
versions of warn (carp) and die (croak) that give the line and file where
the call to the function occurred rather than the line of the carp or croak:

#!/usr/bin/perl

use strict;
use Carp;
use warnings;

sub takes_two {
if (@_ != 2) {
croak "bad number of arguments: [", join(", ", @_), "]";
}
}

sub not_as_good {
if (@_ != 2) {
die "bad number of arguments: [", join(", ", @_), "]";
}
}

eval { takes_two(1, 2, 3); 1 } or warn $@;
eval { not_as_good(1, 2, 3); 1 } or warn $@;


On Sun, Nov 19, 2017 at 1:55 PM Gil Magno  wrote:

> On 19/11/17 15:40, Gil Magno wrote:
> > $num_of_params = scalar @_;
>
> Complementing... In order to get the number of params, you could do
>
> $num_of_params = @_;
>
> without using "scalar @_", because this assignment is already in scalar
> context.
>
> But if you're in list context, you have to use "scalar", as in these
>
> say scalar @_;
> print scalar @_;
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: alternative to feature 'signatures'?

2017-11-19 Thread Gil Magno
On 19/11/17 13:57, hw wrote:
> without being able to use feature 'signatures', how do I verify
> that parameters passed to a function have been passed to it by
> the caller?

If you're dealing with positional parameters[1] (and not with named
ones) you can check for the size of @_ inside your function, that is,
you can check for the quantity of parameters given by the caller.

sub one {
$num_of_params = scalar @_;
print "$num_of_params\n";
}

one('str1'); # prints '1'; there's just one parameter

one('str2', undef); # prints '2'; the second parameter is undef,
# but the undef counts and it prints '2'

[1] Positional parameters would be as in sub_one('John', 'Zimbabwe');
and named parameters as in sub_two({ name => 'John', country =>
'Zimbabwe' });

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: alternative to feature 'signatures'?

2017-11-19 Thread Gil Magno
On 19/11/17 15:40, Gil Magno wrote:
> $num_of_params = scalar @_;

Complementing... In order to get the number of params, you could do

$num_of_params = @_;

without using "scalar @_", because this assignment is already in scalar
context.

But if you're in list context, you have to use "scalar", as in these

say scalar @_;
print scalar @_;

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: alternative to feature 'signatures'?

2017-11-19 Thread Andrew Solomon
This is how I'd go about it:

https://gist.github.com/andrewsolomon/323a2b317ea5903f662fbaaded254798

"exists" is true if there's a key in a hash even if the key's value is
undef.

Does that provide a solution for you, or are there other constraints?

On Sun, Nov 19, 2017 at 4:57 PM, hw  wrote:

>
> Hi,
>
> without being able to use feature 'signatures', how do I verify
> that parameters passed to a function have been passed to it by
> the caller?
>
> A test for undef is not sufficient because the value passed to a
> function may be undef itself, and I need to be able to distinguish
> between the parameter having been passed (and is undef) and the
> parameter not having been passed at all.
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 
Andrew Solomon

Mentor@Geekuni http://geekuni.com/
http://www.linkedin.com/in/asolomon


alternative to feature 'signatures'?

2017-11-19 Thread hw


Hi,

without being able to use feature 'signatures', how do I verify
that parameters passed to a function have been passed to it by
the caller?

A test for undef is not sufficient because the value passed to a
function may be undef itself, and I need to be able to distinguish
between the parameter having been passed (and is undef) and the
parameter not having been passed at all.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/