Git Product home page Git Product logo

Comments (7)

tobyink avatar tobyink commented on August 26, 2024

Really the whole question of what is and is not considered a file handle in Perl is a little muddy. Whether IO::String objects should be considered to be file handles could be argued either way. I don't think either behaviour you observe is really incorrect, however it would be nice if they were consistent.

Do you have a suggested fix?

from p5-type-tiny.

tsibley avatar tsibley commented on August 26, 2024

I think making Types::Standard match the Type::Tiny::XS behaviour (i.e. considering IO::String a FileHandle) is more desirable.

I don't have a patch because I was not quite able to follow the XS function enough to spot the difference between the pure Perl check and the check in C.

from p5-type-tiny.

tsibley avatar tsibley commented on August 26, 2024

To clarify, I do agree it could be argued either way. As long as it's consistent, that's fine by me. Personally, I think IO::String should be considered a FileHandle.

from p5-type-tiny.

tobyink avatar tobyink commented on August 26, 2024

Okay, so the current pure Perl check is:

	(ref($_) eq "GLOB" && Scalar::Util::openhandle($_))
	or (blessed($_) && $_->isa("IO::Handle"))

I think it can be made consistent with the XS by changing it to:

	(Scalar::Util::reftype($_) eq "GLOB" && Scalar::Util::openhandle($_))
	or (blessed($_) && $_->isa("IO::Handle"))

Advantages:

  • Makes Type::Tiny and Type::Tiny::XS consistent.
  • Allows IO::String to pass the type constraint.
  • Makes Type::Tiny and Mouse consistent.

Disadvantages:

  • Inconsistent with Moose.
  • Breaks encapsulation by caring about the reftype of a blessed object.

from p5-type-tiny.

tobyink avatar tobyink commented on August 26, 2024

MooX::Types::MooseLike::Base uses this check:

(defined($_) && Scalar::Util::openhandle($_))
or (blessed($_) && $_->isa("IO::Handle"))

That's a fairly nice solution. Doesn't break encapsulation. The following might fail faster in the case of non-references:

(ref($_) && Scalar::Util::openhandle($_))
or (blessed($_) && $_->isa("IO::Handle"))

from p5-type-tiny.

tobyink avatar tobyink commented on August 26, 2024

Moved to RT.
https://rt.cpan.org/Ticket/Display.html?id=121762

from p5-type-tiny.

tobyink avatar tobyink commented on August 26, 2024

Fixed in dev version 1.003_001.

from p5-type-tiny.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.