Open p5pRT opened 14 years ago
The API function sv_does is broken\, and has been since it was first introduced. What it actually implements is a correct Perl-level ->isa check\, which is useful\, but not the same as a ->DOES check.
The logic currently in Perl_sv_does for checking ->isa should be moved into XS_UNIVERSAL_DOES\, and Perl_sv_does itself should just do a normal ->DOES method call. (The checks for 'is this an object' should probably stay.)
It might be useful to add a sv_perl_isa API\, which does a proper overridable ->isa check\, but that is a separate question.
Ben
The correct way to test for DOES (or isa\, or can) is to just call the method directly. I'm not sure that providing wrappers around this in the perl core is particularly useful.
That said\, I am kind of curious what the actual use for making sv_does a public API function is.
The RT System itself - Status changed from 'new' to 'open'
On 24 June 2012 03:22\, Jesse Luehrs via RT \perlbug\-followup@​perl\.org wrote:
The correct way to test for DOES (or isa\, or can) is to just call the method directly. I'm not sure that providing wrappers around this in the perl core is particularly useful.
That said\, I am kind of curious what the actual use for making sv_does a public API function is.
When does was introduced there was a lot of debate about whether it made sense. I was one of the people who argued it didnt\, and provided patches to make it make sense.
Now that is has been available in the wild for some time I it is clear to me it has failed as an idea exactly as predicted.
Maybe I should get my patches together and we can get a DOES that does.
Yves
-- perl -Mre=debug -e "/just|another|perl|hacker/"
On Saturday\, June 23\, 2012 06:22:34 PM Jesse Luehrs via RT wrote:
The correct way to test for DOES (or isa\, or can) is to just call the method directly. I'm not sure that providing wrappers around this in the perl core is particularly useful.
That seems sanest to me.
That said\, I am kind of curious what the actual use for making sv_does a public API function is.
If I recall correctly\, it only exists and is public because sv_isa exists and is public. sv_does is clearly broken unless it calls the method directly.
-- c
On Sun Jun 24 09:50:04 2012\, chromatic@wgz.org wrote:
On Saturday\, June 23\, 2012 06:22:34 PM Jesse Luehrs via RT wrote:
The correct way to test for DOES (or isa\, or can) is to just call the method directly. I'm not sure that providing wrappers around this in the perl core is particularly useful.
That seems sanest to me.
That said\, I am kind of curious what the actual use for making sv_does a public API function is.
If I recall correctly\, it only exists and is public because sv_isa exists and is public. sv_does is clearly broken unless it calls the method directly.
UNIVERSAL::DOES is implemented in terms of sv_does\, so we can’t ‘just’ make it call the method. I think the real bug is that it is in the API. But there are many weird and useless functions in the API that we can’t get rid of.
--
Father Chrysostomos
On Sun\, Jun 24\, 2012 at 11:06:09AM -0700\, Father Chrysostomos via RT wrote:
On Sun Jun 24 09:50:04 2012\, chromatic@wgz.org wrote:
On Saturday\, June 23\, 2012 06:22:34 PM Jesse Luehrs via RT wrote:
The correct way to test for DOES (or isa\, or can) is to just call the method directly. I'm not sure that providing wrappers around this in the perl core is particularly useful.
That seems sanest to me.
That said\, I am kind of curious what the actual use for making sv_does a public API function is.
If I recall correctly\, it only exists and is public because sv_isa exists and is public. sv_does is clearly broken unless it calls the method directly.
UNIVERSAL::DOES is implemented in terms of sv_does\, so we can’t ‘just’ make it call the method. I think the real bug is that it is in the API. But there are many weird and useless functions in the API that we can’t get rid of.
Yes\, the implementation of UNIVERSAL::DOES is fine\, the only confusing part is that sv_does is a public API function.
-doy
On 06/24/2012 08:06 PM\, Father Chrysostomos via RT wrote:
UNIVERSAL::DOES is implemented in terms of sv_does\, so we can’t ‘just’ make it call the method. I think the real bug is that it is in the API. But there are many weird and useless functions in the API that we can’t get rid of.
But we can move them to a section "for back-compat only" in perlapi.pod to make sure that sane but uninformed people don't call these functions in new code.
--Steffen
Jesse Luehrs \doy@​tozt\.net writes:
Yes\, the implementation of UNIVERSAL::DOES is fine\, the only confusing part is that sv_does is a public API function.
Last year we had a discussion about this.
DOES\, as it is implemented right now\, is bogus and wrong. The documentation talks about DOES in combination with roles but there are no roles in Perl. Adding "A role is ..." to the documentation of DOES doens't really help\, especially since Perlootut reads:
"Perl does not have any built-in way to express roles. [...] As we mentioned before\, roles provide an alternative to inheritance\, but Perl does not have any built-in role support. If you choose to use Moose\, it comes with a full-fledged role implementation. However\, if you use one of our other recommended OO modules\, you can still use roles with Role::Tiny [...]".
So there are no roles in Perl\, but there are some CPAN modules that implement something role-like. Differently. Role::Tiny documents:
if (Role::Tiny::does_role($foo\, 'Some::Role')) { ... }
And:
if ($foo->does('Some::Role')) { ... }
So it does not even use\, or advise to use\, DOES. Neither does Moo. In fact there's no need at all for DOES since said CPAN modules provide their own methods to check whether a class provides a role.
I repeat from \m2mxiy48bv\.fsf@​phoenix\.squirrel\.nl :
[...] But since there's no documentation about roles people may use DOES as they think fit -- and we have yet another coffin nail that we can never get rid of anymore due to compatibility purposes.
-- Johan
On 24 June 2012 21:57\, Johan Vromans \jvromans@​squirrel\.nl wrote:
Jesse Luehrs \doy@​tozt\.net writes:
Yes\, the implementation of UNIVERSAL::DOES is fine\, the only confusing part is that sv_does is a public API function.
Last year we had a discussion about this.
DOES\, as it is implemented right now\, is bogus and wrong. The documentation talks about DOES in combination with roles but there are no roles in Perl. Adding "A role is ..." to the documentation of DOES doens't really help\, especially since Perlootut reads:
"Perl does not have any built-in way to express roles. [...] As we mentioned before\, roles provide an alternative to inheritance\, but Perl does not have any built-in role support. If you choose to use Moose\, it comes with a full-fledged role implementation. However\, if you use one of our other recommended OO modules\, you can still use roles with Role::Tiny [...]".
So there are no roles in Perl\, but there are some CPAN modules that implement something role-like. Differently. Role::Tiny documents:
if (Role::Tiny::does_role($foo\, 'Some::Role')) { ... }
And:
if ($foo->does('Some::Role')) { ... }
So it does not even use\, or advise to use\, DOES. Neither does Moo. In fact there's no need at all for DOES since said CPAN modules provide their own methods to check whether a class provides a role.
I repeat from \m2mxiy48bv\.fsf@​phoenix\.squirrel\.nl :
[...] But since there's no documentation about roles people may use DOES as they think fit -- and we have yet another coffin nail that we can never get rid of anymore due to compatibility purposes.
It is savable IMO. I posted a patch at the time to make it useful. Reattached again here.
Thread is available here:
http://www.nntp.perl.org/group/perl.perl5.porters/2007/03/msg122105.html
cheers\, Yves
-- perl -Mre=debug -e "/just|another|perl|hacker/"
On Sun Jun 24 23:48:39 2012\, demerphq wrote:
On 24 June 2012 21:57\, Johan Vromans \jvromans@​squirrel\.nl wrote:
Jesse Luehrs \doy@​tozt\.net writes:
Yes\, the implementation of UNIVERSAL::DOES is fine\, the only confusing part is that sv_does is a public API function.
Last year we had a discussion about this.
DOES\, as it is implemented right now\, is bogus and wrong. The documentation talks about DOES in combination with roles but there are no roles in Perl. Adding "A role is ..." to the documentation of DOES doens't really help\, especially since Perlootut reads:
�"Perl does not have any built-in way to express roles. �[...] As we mentioned before\, roles provide an alternative to �inheritance\, but Perl does not have any built-in role support. If you �choose to use Moose\, it comes with a full-fledged role implementation. �However\, if you use one of our other recommended OO modules\, you can �still use roles with Role::Tiny [...]".
So there are no roles in Perl\, but there are some CPAN modules that implement something role-like. Differently. Role::Tiny documents:
�if (Role::Tiny::does_role($foo\, 'Some::Role')) { � ... �}
And:
�if ($foo->does('Some::Role')) { � �... �}
So it does not even use\, or advise to use\, DOES. Neither does Moo. In fact there's no need at all for DOES since said CPAN modules provide their own methods to check whether a class provides a role.
I repeat from \m2mxiy48bv\.fsf@​phoenix\.squirrel\.nl :
�[...] But since there's no documentation about roles people may use �DOES as they think fit -- and we have yet another coffin nail that we �can never get rid of anymore due to compatibility purposes.
It is savable IMO. I posted a patch at the time to make it useful. Reattached again here.
Thread is available here:
http://www.nntp.perl.org/group/perl.perl5.porters/2007/03/msg122105.html
Having UNIVERSAL::DOES call the method could cause infinite looping if someone says sub DOES { goto &UNIVERSAL::does } (whether in a subclass or a wrapper).
Having built-in roles like qr// sounds like a nice idea\, but don’t we already have that with Regexp\, HASH\, ARRAY\, etc.?
--
Father Chrysostomos
On 25 June 2012 15:28\, Father Chrysostomos via RT \perlbug\-followup@​perl\.org wrote:
On Sun Jun 24 23:48:39 2012\, demerphq wrote:
On 24 June 2012 21:57\, Johan Vromans \jvromans@​squirrel\.nl wrote:
Jesse Luehrs \doy@​tozt\.net writes:
Yes\, the implementation of UNIVERSAL::DOES is fine\, the only confusing part is that sv_does is a public API function.
Last year we had a discussion about this.
DOES\, as it is implemented right now\, is bogus and wrong. The documentation talks about DOES in combination with roles but there are no roles in Perl. Adding "A role is ..." to the documentation of DOES doens't really help\, especially since Perlootut reads:
�"Perl does not have any built-in way to express roles. �[...] As we mentioned before\, roles provide an alternative to �inheritance\, but Perl does not have any built-in role support. If you �choose to use Moose\, it comes with a full-fledged role implementation. �However\, if you use one of our other recommended OO modules\, you can �still use roles with Role::Tiny [...]".
So there are no roles in Perl\, but there are some CPAN modules that implement something role-like. Differently. Role::Tiny documents:
�if (Role::Tiny::does_role($foo\, 'Some::Role')) { � ... �}
And:
�if ($foo->does('Some::Role')) { � �... �}
So it does not even use\, or advise to use\, DOES. Neither does Moo. In fact there's no need at all for DOES since said CPAN modules provide their own methods to check whether a class provides a role.
I repeat from \m2mxiy48bv\.fsf@​phoenix\.squirrel\.nl :
�[...] But since there's no documentation about roles people may use �DOES as they think fit -- and we have yet another coffin nail that we �can never get rid of anymore due to compatibility purposes.
It is savable IMO. I posted a patch at the time to make it useful. Reattached again here.
Thread is available here:
http://www.nntp.perl.org/group/perl.perl5.porters/2007/03/msg122105.html
Having UNIVERSAL::DOES call the method could cause infinite looping if someone says sub DOES { goto &UNIVERSAL::does } (whether in a subclass or a wrapper).
The patch explains how to do this properly doesn't it?
+B\<WARNING:> the delegation behaviour of UNIVERSAL::DOES() means that if a
+custom DOES() method wishes to call the default method provided by UNIVERSAL\,
+such as via C\<$self->SUPER::DOES($role)> then it B\
Im not thrilled that this edge case is a possibility but I figured it was simple enough to say "well dont do that then"\, although I suspect these days I could figure out a block\, albeit at potentially a performance trade off to prevent people from being overly stupid. But IMO you could make exactly the same argument about a number of places couldn't you? Can't I infinite loop if I create an overload sub with a similar level of carelessness? Does that mean we should rip out overload?
cheers\, Yves
-- perl -Mre=debug -e "/just|another|perl|hacker/"
On 25 June 2012 15:34\, demerphq \demerphq@​gmail\.com wrote:
But IMO you could make exactly the same argument about a number of places couldn't you? Can't I infinite loop if I create an overload sub with a similar level of carelessness? Does that mean we should rip out overload?
Eg:
cat perl overload_inf.pl cat: perl: No such file or directory package Foo; use overload '""'=> \&stringify;
sub stringify { print "in stringify\n"; return "" . $_[0]; }
my $obj= bless {}\,"Foo"; print $obj
Also loops infinitely and eventually segfaults perl. So to the extent your comment is criticism of my patch\, I think its a bit unfair to apply it in this case given we have loads of other cases where it also applies.
Yves
-- perl -Mre=debug -e "/just|another|perl|hacker/"
On Mon\, Jun 25\, 2012 at 08:48:00AM +0200\, demerphq wrote:
On 24 June 2012 21:57\, Johan Vromans \jvromans@​squirrel\.nl wrote:
Jesse Luehrs \doy@​tozt\.net writes:
Yes\, the implementation of UNIVERSAL::DOES is fine\, the only confusing part is that sv_does is a public API function.
Last year we had a discussion about this.
DOES\, as it is implemented right now\, is bogus and wrong. The documentation talks about DOES in combination with roles but there are no roles in Perl. Adding "A role is ..." to the documentation of DOES doens't really help\, especially since Perlootut reads:
"Perl does not have any built-in way to express roles. [...] As we mentioned before\, roles provide an alternative to inheritance\, but Perl does not have any built-in role support. If you choose to use Moose\, it comes with a full-fledged role implementation. However\, if you use one of our other recommended OO modules\, you can still use roles with Role::Tiny [...]".
So there are no roles in Perl\, but there are some CPAN modules that implement something role-like. Differently. Role::Tiny documents:
if (Role::Tiny::does_role($foo\, 'Some::Role')) { ... }
And:
if ($foo->does('Some::Role')) { ... }
So it does not even use\, or advise to use\, DOES. Neither does Moo. In fact there's no need at all for DOES since said CPAN modules provide their own methods to check whether a class provides a role.
I repeat from \m2mxiy48bv\.fsf@​phoenix\.squirrel\.nl :
[...] But since there's no documentation about roles people may use DOES as they think fit -- and we have yet another coffin nail that we can never get rid of anymore due to compatibility purposes.
It is savable IMO. I posted a patch at the time to make it useful. Reattached again here.
Thread is available here:
http://www.nntp.perl.org/group/perl.perl5.porters/2007/03/msg122105.html
cheers\, Yves
So I like the general concept here\, but I don't know if I'm a huge fan of the implementation. Requiring the hack that you have to explicitly say "don't recurse" is a bit ugly\, and the only reason it's necessary is because you're forcing UNIVERSAL::DOES to be able to be called as both a function and a method. This is concerning because of the amount of effort that we have had to put in to convince people to *not* do this with UNIVERSAL::isa and UNIVERSAL::can\, because they do not handle this sort of thing properly.
I think this would work a lot better if UNIVERSAL::DOES was only called as a method\, and a new keyword/function of some sort were introduced to either call DOES as a method on its argument\, or handle the various things that can't have methods called on them (or alternately\, we can wait until autoboxing gets into core? (: ).
-doy
On 25 June 2012 16:43\, Jesse Luehrs \doy@​tozt\.net wrote:
I think this would work a lot better if UNIVERSAL::DOES was only called as a method\, and a new keyword/function of some sort were introduced to either call DOES as a method on its argument\, or handle the various things that can't have methods called on them (or alternately\, we can wait until autoboxing gets into core? (: ).
This doesnt fly as you then restrict the use of DOES to objects and you have to guard any use of it with a blessed() check\, which is IMO one of the reasons why it goes almost completely unused in production code.
Perhaps there is an alternative but "must be called as a method" isn't the right one.
cheers Yves
-- perl -Mre=debug -e "/just|another|perl|hacker/"
On Mon\, Jun 25\, 2012 at 04:59:18PM +0200\, demerphq wrote:
On 25 June 2012 16:43\, Jesse Luehrs \doy@​tozt\.net wrote:
I think this would work a lot better if UNIVERSAL::DOES was only called as a method\, and a new keyword/function of some sort were introduced to either call DOES as a method on its argument\, or handle the various things that can't have methods called on them (or alternately\, we can wait until autoboxing gets into core? (: ).
This doesnt fly as you then restrict the use of DOES to objects and you have to guard any use of it with a blessed() check\, which is IMO one of the reasons why it goes almost completely unused in production code.
Perhaps there is an alternative but "must be called as a method" isn't the right one.
No\, you misunderstood - introduce a new separate keyword which itself calls DOES as a method on objects\, and does whatever is appropriate for non-objects. This way\, you can do "if (does([]\, '@{}'))" or "if (does(Foo->new\, 'SomeRole'))" and have both of those do sensible things\, without having the issue of having to hack things around in order to make UNIVERSAL::DOES callable as a function.
-doy
On 25 June 2012 17:04\, Jesse Luehrs \doy@​tozt\.net wrote:
On Mon\, Jun 25\, 2012 at 04:59:18PM +0200\, demerphq wrote:
On 25 June 2012 16:43\, Jesse Luehrs \doy@​tozt\.net wrote:
I think this would work a lot better if UNIVERSAL::DOES was only called as a method\, and a new keyword/function of some sort were introduced to either call DOES as a method on its argument\, or handle the various things that can't have methods called on them (or alternately\, we can wait until autoboxing gets into core? (: ).
This doesnt fly as you then restrict the use of DOES to objects and you have to guard any use of it with a blessed() check\, which is IMO one of the reasons why it goes almost completely unused in production code.
Perhaps there is an alternative but "must be called as a method" isn't the right one.
No\, you misunderstood - introduce a new separate keyword which itself calls DOES as a method on objects\, and does whatever is appropriate for non-objects. This way\, you can do "if (does([]\, '@{}'))" or "if (does(Foo->new\, 'SomeRole'))" and have both of those do sensible things\, without having the issue of having to hack things around in order to make UNIVERSAL::DOES callable as a function.
Ah. Yes I did misunderstand. Thanks for clarifying.
Yves
-- perl -Mre=debug -e "/just|another|perl|hacker/"
[Quoting Jesse Luehrs\, on June 25 2012\, 10:04\, in "Re: [perl #77256] sv"]
introduce a new separate keyword which itself calls DOES as a method on objects\, and does whatever is appropriate for non-objects. This way\, you can do "if (does([]\, '@{}'))"
Great! Finally we'd get rid of isa($foo\, 'ARRAY') ...
-- Johan
On 25 June 2012 18:39\, Johan Vromans \jvromans@​squirrel\.nl wrote:
[Quoting Jesse Luehrs\, on June 25 2012\, 10:04\, in "Re: [perl #77256] sv"]
introduce a new separate keyword which itself calls DOES as a method on objects\, and does whatever is appropriate for non-objects. This way\, you can do "if (does([]\, '@{}'))"
Great! Finally we'd get rid of isa($foo\, 'ARRAY') ...
If Ricardo is fine with something like this then I am willing to do the work to get my patch into shape.
cheers\, Yves
-- perl -Mre=debug -e "/just|another|perl|hacker/"
demerphq \demerphq@​gmail\.com writes:
If Ricardo is fine with something like this then I am willing to do the work to get my patch into shape.
Do we already have a list of predefined rules (like '@{}' that you used as an example earlier)?
On Mon\, Jun 25\, 2012 at 07:46:22PM +0200\, Johan Vromans wrote:
demerphq \demerphq@​gmail\.com writes:
If Ricardo is fine with something like this then I am willing to do the work to get my patch into shape.
Do we already have a list of predefined rules (like '@{}' that you used as an example earlier)?
As long as anywhere that I'm currently doing
"if (ref($foo) eq \
-doy
[Quoting Jesse Luehrs\, on June 25 2012\, 12:56\, in "Re: [perl #77256] sv"]
As long as anywhere that I'm currently doing "if (ref($foo) eq \
)" I can replace with some expression like "if (does($foo\, \ ))"\, I'll be happy.
I'd expect:
my $a = bless []\, "Foo"; say "Foo" if does($a\, 'Foo'); # says "Foo" say "Array" if does($a\, '[]'); # says "Array"
-- Johan
On 25 June 2012 22:25\, Johan Vromans \jvromans@​squirrel\.nl wrote:
[Quoting Jesse Luehrs\, on June 25 2012\, 12:56\, in "Re: [perl #77256] sv"]
As long as anywhere that I'm currently doing "if (ref($foo) eq \
)" I can replace with some expression like "if (does($foo\, \ ))"\, I'll be happy. I'd expect:
my $a = bless []\, "Foo"; say "Foo" if does($a\, 'Foo'); # says "Foo" say "Array" if does($a\, '[]'); # says "Array"
The patch would want you to write that as:
does($a\,"ARRAY")
Just as you would with UNIVERSAL::isa().
but it supports
say "Array-like" if does($a\, '@{}'); # says "Array"
if you wanted to know if you could pretend it was an array.
Yves
-- perl -Mre=debug -e "/just|another|perl|hacker/"
[Quoting demerphq\, on June 25 2012\, 22:42\, in "Re: [perl #77256] sv"]
my $a = bless []\, "Foo"; say "Foo" if does($a\, 'Foo'); # says "Foo" say "Array" if does($a\, '[]'); # says "Array"
The patch would want you to write that as:
does($a\,"ARRAY")
Just as you would with UNIVERSAL::isa().
but it supports
say "Array-like" if does($a\, '@{}'); # says "Array"
if you wanted to know if you could pretend it was an array.
I think we might be missing an opportunity here.
A( ref to a)n array that's blessed seems to me an excellent case for supporting two roles: the array role and the object role. It's not array-like\, it is not less an array as [].
So\, if
does( []\, 'ARRAY' ); # true my $a = []; does( $a\, 'ARRAY' ); # true
then
$a = bless []\, 'Foo'; does( $a\, 'ARRAY'); # should be true as well
Maybe it helps if you explain the difference between
does( ...\, 'ARRAY' )
and
does( ...\, '@{}' )
-- Johan
On Mon\, Jun 25\, 2012 at 10:51:00PM +0200\, Johan Vromans wrote:
[Quoting demerphq\, on June 25 2012\, 22:42\, in "Re: [perl #77256] sv"]
my $a = bless []\, "Foo"; say "Foo" if does($a\, 'Foo'); # says "Foo" say "Array" if does($a\, '[]'); # says "Array"
The patch would want you to write that as:
does($a\,"ARRAY")
Just as you would with UNIVERSAL::isa().
but it supports
say "Array-like" if does($a\, '@{}'); # says "Array"
if you wanted to know if you could pretend it was an array.
I think we might be missing an opportunity here.
A( ref to a)n array that's blessed seems to me an excellent case for supporting two roles: the array role and the object role. It's not array-like\, it is not less an array as [].
So\, if
does( []\, 'ARRAY' ); # true my $a = []; does( $a\, 'ARRAY' ); # true
then
$a = bless []\, 'Foo'; does( $a\, 'ARRAY'); # should be true as well
Maybe it helps if you explain the difference between
does( ...\, 'ARRAY' )
and
does( ...\, '@{}' )
I imagine that does(...\, '@{}') takes overloading into account. One thing that makes this less than ideal though is that $foo->$bar only looks up string overloading on $bar\, and not &{} overloading. It'd be nice if that were fixed\, since it would be a bit misleading for does($o\, '&{}) to be true\, but for $thing->$o to fail.
-doy
On Mon\, 2012-06-25 at 15:55 -0500\, Jesse Luehrs wrote:
On Mon\, Jun 25\, 2012 at 10:51:00PM +0200\, Johan Vromans wrote:
Maybe it helps if you explain the difference between
does( ...\, 'ARRAY' )
and
does( ...\, '@{}' )
I imagine that does(...\, '@{}') takes overloading into account.
It might also be a good idea if it were to ignore the actual type of the blessed hash ref. In most cases if I receive an object instead of a hash\, I only want to use it as such if it makes this intent clear by overloading.
regards\, Robert
On 25 June 2012 22:51\, Johan Vromans \jvromans@​squirrel\.nl wrote:
[Quoting demerphq\, on June 25 2012\, 22:42\, in "Re: [perl #77256] sv"]
my $a = bless []\, "Foo"; say "Foo" if does($a\, 'Foo'); # says "Foo" say "Array" if does($a\, '[]'); # says "Array"
The patch would want you to write that as:
does($a\,"ARRAY")
Just as you would with UNIVERSAL::isa().
but it supports
say "Array-like" if does($a\, '@{}'); # says "Array"
if you wanted to know if you could pretend it was an array.
I think we might be missing an opportunity here.
A( ref to a)n array that's blessed seems to me an excellent case for supporting two roles: the array role and the object role. It's not array-like\, it is not less an array as [].
So\, if
does( []\, 'ARRAY' ); # true my $a = []; does( $a\, 'ARRAY' ); # true
then
$a = bless []\, 'Foo'; does( $a\, 'ARRAY'); # should be true as well
Maybe it helps if you explain the difference between
does( ...\, 'ARRAY' )
Same as isa( ...\, 'ARRAY')\, so it returns true if the reftype(...) eq 'ARRAY' or if the ... was blessed into the 'ARRAY' namespace.
Which actually says you are right and we need a does( ...\, '[]') to tell if it is reftype eq 'ARRAY'.
and
does( ...\, '@{}' )
The idea was to tell you if the object was reftype eq 'ARRAY' OR that there was a '@{}' overload method defined for the object.
Yves
-- perl -Mre=debug -e "/just|another|perl|hacker/"
On Sunday\, June 24\, 2012 09:57:59 PM Johan Vromans wrote:
DOES\, as it is implemented right now\, is bogus and wrong.
So there are no roles in Perl\, but there are some CPAN modules that implement something role-like. Differently. Role::Tiny documents:
if (Role::Tiny::does_role($foo\, 'Some::Role')) { ... }
And:
if ($foo->does('Some::Role')) { ... }
So it does not even use\, or advise to use\, DOES. Neither does Moo.
Any CPAN module which reimplements a part of the core\, badly\, has a bug\, in my opinion.
-- c
[Quoting demerphq\, on June 25 2012\, 23:18\, in "Re: [perl #77256] sv"]
does( ...\, 'ARRAY' )
Same as isa( ...\, 'ARRAY')\, so it returns true if the reftype(...) eq 'ARRAY' or if the ... was blessed into the 'ARRAY' namespace.
Which actually says you are right and we need a does( ...\, '[]') to tell if it is reftype eq 'ARRAY'.
No! This is the fundamental difference between isa and does. does applies to roles and doesn't consider the actual type.
does( $thing\, 'ARRAY' ) being true means I can do $thing->[0] and push( $thing\, ...) and so on. Regardless whether $thing is blessed or whatever.
There are no other array-oriented roles than 'ARRAY'. Overloading must always be taken into account\, that's the whole idea.
-- Johan
On 26 June 2012 08:09\, Johan Vromans \jvromans@​squirrel\.nl wrote:
[Quoting demerphq\, on June 25 2012\, 23:18\, in "Re: [perl #77256] sv"]
does( ...\, 'ARRAY' )
Same as isa( ...\, 'ARRAY')\, so it returns true if the reftype(...) eq 'ARRAY' or if the ... was blessed into the 'ARRAY' namespace.
Which actually says you are right and we need a does( ...\, '[]') to tell if it is reftype eq 'ARRAY'.
No! This is the fundamental difference between isa and does. does applies to roles and doesn't consider the actual type. does( $thing\, 'ARRAY' ) being true means I can do $thing->[0] and push( $thing\, ...) and so on. Regardless whether $thing is blessed or whatever.
There are no other array-oriented roles than 'ARRAY'. Overloading must always be taken into account\, that's the whole idea.
No no. Sometime you WANT an AV and I dont see how its useful to force a mental model on devs that forbids then doing something want to do.
This is part of the point for me\, DOES and Perls OO model shouldnt enforce restrictive models on the user base. We should provide the tools they need to make intelligent decisions on their own. That to me is the nature of Perl.
Cheers\, yves
-- perl -Mre=debug -e "/just|another|perl|hacker/"
[Quoting demerphq\, on June 26 2012\, 08:49\, in "Re: [perl #77256] sv"]
No no. Sometime you WANT an AV and I dont see how its useful to force a mental model on devs that forbids then doing something want to do.
Yes\, naturally. Only that's not a role for does\, we have reftype for that.
This is part of the point for me\, DOES and Perls OO model shouldnt enforce restrictive models on the user base. We should provide the tools they need to make intelligent decisions on their own. That to me is the nature of Perl.
You risk ending up with several functions with much overlapping functionality. That is confusing and error prone.
-- Johan
On 26 June 2012 09:14\, Johan Vromans \jvromans@​squirrel\.nl wrote:
[Quoting demerphq\, on June 26 2012\, 08:49\, in "Re: [perl #77256] sv"]
No no. Sometime you WANT an AV and I dont see how its useful to force a mental model on devs that forbids then doing something want to do.
Yes\, naturally. Only that's not a role for does\, we have reftype for that.
I want one routine that I can use for all of it.
This is part of the point for me\, DOES and Perls OO model shouldnt enforce restrictive models on the user base. We should provide the tools they need to make intelligent decisions on their own. That to me is the nature of Perl.
You risk ending up with several functions with much overlapping functionality. That is confusing and error prone.
Like pack? I think the uses are related enough that people wont be confused.
Yves
-- perl -Mre=debug -e "/just|another|perl|hacker/"
[Quoting demerphq\, on June 26 2012\, 09:19\, in "Re: [perl #77256] sv"]
I want one routine that I can use for all of it.
Let's agree to disagree\, then.
-- Johan
On Tue\, 2012-06-26 at 09:19 +0200\, demerphq wrote:
On 26 June 2012 09:14\, Johan Vromans \jvromans@​squirrel\.nl wrote:
Yes\, naturally. Only that's not a role for does\, we have reftype for that.
I want one routine that I can use for all of it.
That would mean the check would break encapsulation by default. It means I can't use it in any of the use-cases I'd like to use it in. And having a core utility suggest that poking my objects is OK because I chose to implement them as a blessed hash ref seems wrong. In my mind\, that's what overloading is for.
This is part of the point for me\, DOES and Perls OO model shouldnt enforce restrictive models on the user base. We should provide the tools they need to make intelligent decisions on their own. That to me is the nature of Perl.
You risk ending up with several functions with much overlapping functionality. That is confusing and error prone.
Like pack? I think the uses are related enough that people wont be confused.
In my mind\, 'does' & Co. are about intents. An unblessed hash reference is intended to be used as a hash reference. An object overloading hash access is intended for usage as hash reference. But you can not assume an object likes to be treated as a hash reference just because its storage is based on it. I'd guess that "does this value want to be treated like a hash?" is a question asked much more often than "Is this a hash or something using one to implement an object?".
If an object would _want_ to be used as a hash reference\, it could just override DOES and return true on whatever it wants.
regards\, Robert
Robert Sedlacek \rs@​474\.at writes:
If an object would _want_ to be used as a hash reference\, it could just override DOES and return true on whatever it wants.
This would make more sense if perl had opaque objects. But I won't mind a more stricter 'does'.
-- Johan
On Tue\, 2012-06-26 at 17:23 +0200\, Johan Vromans wrote:
Robert Sedlacek \rs@​474\.at writes:
If an object would _want_ to be used as a hash reference\, it could just override DOES and return true on whatever it wants.
This would make more sense if perl had opaque objects. But I won't mind a more stricter 'does'.
It might make more sense\, but I think it makes enough already\, at least to me :) 'does' would tell you for every normal object that it wants to be treated as opaque. If one wants to use blessing just as a way of having a hash reference with methods\, it could be as easy as
use intent::hash; # provides a DOES that is true for hash access
I can certainly see the value of reftype and co\, sometimes you want to act on a object on a different level than usage\, like serialisation and transmission\, as well as debugging. But I think these are more special use cases than simply determining if I can use a value like I intend to\, or decide what to do with it depending on how it is intended to be used.
regards\, Robert
Robert Sedlacek \rs@​474\.at writes:
If one wants to use blessing just as a way of having a hash reference with methods\, it could be as easy as
use intent::hash; # provides a DOES that is true for hash access
That's precisely what I was thinking of. A nice\, clean and elegant way to achieve the desired behaviour without the need to (re)define magic subroutines.
+1
-- Johan
On Mon Aug 16 16:02:16 2010\, ben@morrow.me.uk wrote:
The API function sv_does is broken\, and has been since it was first introduced. What it actually implements is a correct Perl-level ->isa check\, which is useful\, but not the same as a ->DOES check.
The logic currently in Perl_sv_does for checking ->isa should be moved into XS_UNIVERSAL_DOES\, and Perl_sv_does itself should just do a normal ->DOES method call. (The checks for 'is this an object' should probably stay.)
It might be useful to add a sv_perl_isa API\, which does a proper overridable ->isa check\, but that is a separate question.
Ben
I reviewed this older ticket tonight. What I quote above was the original post. Discussion continued from August 2010 to June 2012\, but at no point was a patch submitted. The discussion was of the kind that we have a lot of on the p5p mailing list and probably should have been conducted there.
I would like to ask those who posted to review their comments and\, as appropriate\, either (a) post on p5p; or (b) open new RT tickets *with patches*.
I am taking this ticket for the purpose of closing it within 7 days unless someone wishes to take it over and move the discussion forward.
Thank you very much. Jim Keenan
Migrated from rt.perl.org#77256 (status was 'open')
Searchable as RT77256$