-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More scalar utilities #42
Comments
I'll pick this one up. |
trim/ltrim/rtrim: done still todo:
|
All the trims are merged in |
The perlfaq4 stuff is merged in. |
Cool, thanks for finishing that stuff up. This issue is still open, so is there anything else that I should start or is this just waiting to be closed? |
is a regex, object/instance, and reference didn't make it in IIRC. Neither is array, scalar, hash, glob, etc... |
So I started digging in to this one again but it seems that UNIVERSAL.pm is not the right place for this as the object is not yet an object enough to call ->mo from? Is there a better place to put things like is_instance? Or should each type (ie SCALAR, ARRAY... ) overwrite the stub with the same code? |
These weren't conceived as meta methods. If they were put in like They probably should be meta methods, I don't think the concept existed when this issue was written, to avoid polluting the universal namespace. In that case they go into I'd also suggest |
The way that I was thinking of it would be that we have both is_instance and is_object but they mean different things. In the case of $thing->is_instance('CLASS') then this should check $thing->mo->linear_isa for 'CLASS' and if no match is found then ask $thing->mo->reftype if it's 'CLASS'. This will allow us then to say that is_array is really just is_instance('ARRAY') to allow for a blessed array to still be is_array. Then for is_ref is just a boolean check around reftype and is_object is just linear_isa[0] ne reftype . But my complication is that this line of thinking relies completely on having mo handy, and it seems that in UNIVERSAL the value is not yet an object enough to have ->mo. Should I approach this one from another direction? |
If I understand, you want
I'm not sure I follow your example of wanting to check that an array is an array class or an array ref. What situation would that be useful?
And this doesn't go into |
Yes, though I was thinking of using linear_isa as it always goes back to UNIVERSAL even for the cases of refs because of autobox. Then is_array would still work in all cases. Or it's also completely possible that I'm 100% mistaken in both my understating of what linear_isa is in comparison to isa as well as the goal here. As to is_object, good point about using SU::blessed, that will be far more reliable then what I had been thinking. Lastly I think that there is still some confusion on the UNIVERSAL v Meta issue. If we look at your method of is_instance, it seems that this should exist for all the autobox classes, thus it should live in UNIVERSAL (ie $thing->is_instance('Thingie'), rather then $thing->mo->is_instance('Thingie')) But if you include such a method in UNIVERSAL, it all blows up:
if you convert it to a sub: sub is_instance{
my ($self,$class_or_reftype) = @_;
return $self->isa($class_or_reftype);
} Then the error is now:
Thus if we really want to have $thing->is_instance('Thingie') then it seems that we can not have access to mo? Is this a timing thing? Or again is this just further proof that I've missed the thought train on this one? |
Oop, I realized that I did not include the test: #!/usr/bin/env perl
use perl5i::latest;
use Test::Most;
my $array = [];
ok $array->is_instance('ARRAY'); |
We worked out a couple things at the PDX Hackathon last night... Things is in autobox don't affect blessed objects. This means putting things in perl5i::2::UNIVERSAL isn't like putting things into UNIVERSAL, which is good. We clarified what goes into perl5i::2::UNIVERSAL and what goes into perl5i::2::Meta (ie. More practically, autoboxed methods don't work on blessed objects. A simpler way to think about it is if a method is supposed to apply to everything it should be I'll update the wiki and put some comments in the relevant modules. |
…does what is_instance was intended to do thus I am dropping is_instance.
trim (strip whitespace), ltrim, rtrim
is a number
is an integer, decimal... all the stuff from perlfaq4
is a regex
is an object/instance
is a reference
The text was updated successfully, but these errors were encountered: