Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 132539
Status: rejected
Priority: 0/
Queue: Type-Tiny

People
Owner: Nobody in particular
Requestors: ben.whosgonna.com [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: StrMatch[] warns "Use of uninitialized value $_ in pattern match (m//)" and fails to validate properly
Date: Sun, 10 May 2020 08:41:39 -0500
To: bug-Type-Tiny [...] rt.cpan.org
From: B K <ben.whosgonna.com [...] gmail.com>
Hello, I hope I'm using this correctly, but when i try to use StrMatch, I get a warning message that "Use of uninitialized value $_ in pattern match (m//)". Additionally, invalid values do not fail validation. My sample code: ----- use strict; use warnings; use Types::Standard 'StrMatch'; my $type = StrMatch[/foo/]; my $str = 'bar'; $type->assert_valid($str); print "Didn't die\n"; ----- Running this gives: Show quoted text
> Use of uninitialized value $_ in pattern match (m//) at
./TypesStandard_StrMatch_test.pl line 5. Show quoted text
> Didn't die
Perhaps I'm misreading the documentation or something similar. Regards, Ben Kaufman
On Sun May 10 09:41:56 2020, ben.whosgonna.com@gmail.com wrote: Show quoted text
> Hello, > > I hope I'm using this correctly, but when i try to use StrMatch, I get a > warning message that "Use of uninitialized value $_ in pattern match > (m//)". Additionally, invalid values do not fail validation. > > My sample code: > ----- > use strict; > use warnings; > use Types::Standard 'StrMatch'; > > my $type = StrMatch[/foo/]; > my $str = 'bar'; > > $type->assert_valid($str); > print "Didn't die\n"; > ----- > > Running this gives:
> > Use of uninitialized value $_ in pattern match (m//) at
> ./TypesStandard_StrMatch_test.pl line 5.
> > Didn't die
> > > Perhaps I'm misreading the documentation or something similar. > > Regards, > Ben Kaufman
The parameter to StrMatch needs to be a regex object, as created by qr//. Instead, you are using a regex match directly, which perl evaluates immediately. This tries to match against $_, giving you the uninitialized warning, and returning an empty list. This leaves you with the equivalent of the type StrMatch[], so it accepts any string. What you want instead is: my $type = StrMatch[qr/foo/];
What haarg said is correct.