What I need is a way to, possibly recursively, check structures for type -- for instance, one should be able to check if it matches certain regexen, for strings, or isa a certain class, or isa a certain type, or contains only elements or keys of certain types, or returns true when given as the argument to a supplied coderef, etc. So I planned it out and coded it. Originally I was going to use Quantum::Superpositions rather than grep here, but it produced copious amounts of warnings with -w, so I used grep instead, which didn't.
The problem I'm having is that when given certain pieces of data that should not match the template given, it returns true anyway.
The relevant section of code:
The data and type template, Data::Dentered:sub typeck { my ($what, $type) = @_; if (!UNIVERSAL::isa($type, 'ARRAY')) { croak 'Type not an array re +ference' } not grep { !$_ } ( map { grep { $_ } ( (index($_, '/') == 1 and rindex($_, '/') == (length($_) - 1 +) and do { my $rex = substr($_, 1, length($_) - 1); (ref($what) eq '') ? ($what =~ $rex) : ((Denter $what) =~ $ +rex); }), (UNIVERSAL::isa($_, 'ARRAY') && do { my $type = $_; not grep {!$_} (map { typeck ($_, $type) } ((UNIVERSAL::isa($what, 'ARRAY' +)) ? @$what : values(%$what))); }), (UNIVERSAL::isa($_, 'HASH') && do { my $type = $_; not grep {!$_} (map { exists ($type->{$_}) } (keys %$what)); }), (UNIVERSAL::isa($_, 'CODE') && $_->($what)), (UNIVERSAL::isa($what, $_))) } (@$type)); }
# -- data --
@
10
345
badvalue
49120
# -- type --
@
ARRAY
@
/^0-9+$/
When run, &typeck seems to be skipping entirely over the template, returning 1 always. I looked through the code and found no errors, and the Perl debugger was of no help, so I turn to the monks for help.
Can anyone figure out what is going on here?
In reply to Type checker not checking out by premchai21
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |