Skip to content
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

Fix Type::Tiny->can and AUTOLOAD when the class "can't" #57

Merged
merged 2 commits into from
Aug 4, 2020

Conversation

merrilymeredith
Copy link
Contributor

Hi! I caught this issue today after a dependency update. The change introduced here:

d11d043#diff-2d2f4240c6e6b48948f2efbb94166f60R1234

causes the following exception when can and AUTOLOAD are called as class methods and are falling through to return nada because they can't:

Can't use string ("Type::Tiny") as a HASH ref while "strict refs" in use at /usr/local/share/perl/5.26.1/Type/Tiny.pm line 1305.
        Type::Tiny::can("Type::Tiny", "foobaz") called at reply input line 1

AUTOLOAD hits the same thing rather than reaching the croak "Can't locate ..."

I added a test for can/can't cases, hopefully in a good spot, and then moved the entire offending section within the if (ref($self)) just above it, in both methods.

@codecov
Copy link

codecov bot commented Aug 3, 2020

Codecov Report

Merging #57 into master will increase coverage by 0.02%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #57      +/-   ##
==========================================
+ Coverage   88.78%   88.80%   +0.02%     
==========================================
  Files          36       36              
  Lines        3583     3583              
  Branches      984      984              
==========================================
+ Hits         3181     3182       +1     
  Misses         62       62              
+ Partials      340      339       -1     
Impacted Files Coverage Δ
lib/Type/Tiny.pm 88.02% <83.33%> (+0.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 492426d...2c8065c. Read the comment docs.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.602% when pulling 2c8065c on merrilymeredith:fix-class-methods into 492426d on tobyink:master.

@tobyink tobyink merged commit 83bba90 into tobyink:master Aug 4, 2020
clrpackages pushed a commit to clearlinux-pkgs/perl-Type-Tiny that referenced this pull request Aug 27, 2020
… version 1.010003

1.010003	2020-08-08	The Crazy 88

 [ Bug Fixes ]
 - ClassName type constraint should treat empty @isa as if no @isa were
   defined, like Type::Tiny::XS.
   Fixes RT#132583.
   Szymon Nieznański++
   <https://rt.cpan.org/Ticket/Display.html?id=132583>
 - Fix for Type::Tiny->can called as a class method.
   Meredith Howard++
   <tobyink/p5-type-tiny#57>
 - Fix predeclared types in Type::Library.
   Meredith Howard++
   <tobyink/p5-type-tiny#58>

(NEWS truncated at 15 lines)
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Sep 7, 2020
1.010006	2020-09-04

 [ Bug Fixes ]
 - Eliminate recusion warnings when Type::Parser needs to parse complex
   types.
   Fixes RT#121957.
   Diab Jerius++
   <https://rt.cpan.org/Ticket/Display.html?id=121957>

 [ Other ]
 - Better handling of coercions for pre-declared types in Type::Library.
   The type objects created before the type was properly defined will now
   lazily attempt to find coercions from the properly defined type once it
   becomes available.

1.010005	2020-08-26

 - Improvements to $AvoidCallbacks support for
   Type::Tiny::{Class,Role,Duck,Enum,Union,Intersection}, and LaxNum, Ref,
   RegexpRef, FileHandle, Object, Overload, and Tied types from
   Types::Standard.

1.010004	2020-08-18

 [ Bug Fixes ]
 - Fix XSifying Enum[] where the strings contain certain non-word
   characters.
   Andrew Ruder++
   <tobyink/p5-type-tiny-xs#12>
   <tobyink/p5-type-tiny#59>
 - Type::Params compile_named using both the head and named_to_list options
   would cause compilation error.
   Fixes RT#132419.
   Hauke D++
   Sandor Patocs++
   <https://rt.cpan.org/Ticket/Display.html?id=132419>
 - Workaround RT#121957 by avoiding attempting to XSify Enum type
   constraints with more than 50 possible strings.
   Fixes RT#121957.
   Diab Jerius++
   <https://rt.cpan.org/Ticket/Display.html?id=121957>

 [ Documentation ]
 - Link to HTTPS version of Type::Tiny web page.

1.010003	2020-08-08	The Crazy 88

 [ Bug Fixes ]
 - ClassName type constraint should treat empty @isa as if no @isa were
   defined, like Type::Tiny::XS.
   Fixes RT#132583.
   Szymon Nieznański++
   <https://rt.cpan.org/Ticket/Display.html?id=132583>
 - Fix for Type::Tiny->can called as a class method.
   Meredith Howard++
   <tobyink/p5-type-tiny#57>
 - Fix predeclared types in Type::Library.
   Meredith Howard++
   <tobyink/p5-type-tiny#58>

 [ Documentation ]
 - Document some edge cases for Types::Standard Int.
   <https://rt.cpan.org/Ticket/Display.html?id=132754>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants