The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Switch::Perlish::Smatch::Comparators - overall document for comparator behaviour

COMPARATORS

Below is a complete listing of the default comparators that come with Switch::Perlish.

In each comparator description $t refers to the topic and $m refers to the match, or the first and second arguments, respectively.

Array

ARRAY

smatch for an element of @$m in @$t

CODE

call &$m with @$t

HASH

check if an element of @$t exists as a key in %$m

OBJECT

check if an element of @$t exists as a method of $m

Regexp

match $m against the elements of @$t

SCALAR

check if $m points to an element of @$t

UNDEF

return false as $t is already defined

VALUE

smatch for $m in @$t

Code

ARRAY

check if $m refers to $t

CODE

pass %$m to $t

HASH

pass @$m to $t

OBJECT

pass $m to $t

Regexp

pass $m to $t

SCALAR

call $t with $m

VALUE

call $t with $m

Hash

ARRAY

check if an element of @$m exists as a key of %$t

CODE

check if the return from &$m is a hash key of %$t

HASH

check if a key => value pair exists in both %$t and %$m

OBJECT

check if a key of %$t exists as a method of $m

Regexp

check if any keys from %$t match $m

SCALAR

check if $m points to value in %$t

UNDEF

check for an undefined value in %$t (better suggestions welcome)

VALUE

check if $m exists as a key in %$t

Object

ARRAY

if the $t is a blessed ARRAY, delegate to the ARRAY<=>ARRAY comparator

CODE

call the $t on &$m i.e $t->$m

HASH

if the $t is a blessed HASH, delegate to the HASH<=>HASH comparator

OBJECT

check if the $t->isa($m) or the same class (better suggestions welcome)

Regexp

match the class of $t against the $m

SCALAR

check if the $m points to the $t

UNDEF

croak("Can't compare OBJECT with an undef") # suggestions welcome

VALUE

check if $t has $m as a method

Regexp

ARRAY

match $t for every element in @$m

CODE

pass $t to $m

HASH

check if any of keys of %$m match the $t

OBJECT

match $t against $m's class

Regexp

match $m to $t

SCALAR

check if $m refers to $t

UNDEF

croak("Can't compare Regexp with an undef") # suggestions welcome

VALUE

match $t against $m

Scalar

ARRAY

check if $t points to an element of @$m

CODE

check if $t points to $m

HASH

check if $t points to value in %$m

OBJECT

check if the sref refers to the object

Regexp

check if the sref refers to the Regexp object

SCALAR

numerically compare the scalar refs

UNDEF

check if $$t is undef

VALUE

call Switch::Perlish::Smatch::value_cmp() with $$t and $m

Undef

ARRAY

check for an undef in @$m

CODE

pass undef to &$m (to be consistent with other CODE comparators)

HASH

check for an undefined value in %$m (better suggestions welcome)

OBJECT

croak("Can't compare undef with OBJECT") # suggestions welcome

Regexp

croak("Can't compare undef with Regexp") # suggestions welcome

SCALAR

check if $$m is undef

UNDEF

return true as $m is also undefined

VALUE

return false as $m is already defined

Value

ARRAY

check if the $t is in $m

CODE

pass $t to &$m

HASH

check if the $t exists as a key in $m

OBJECT

check if the method $t exists in $m

Regexp

regexp match $t against $m

SCALAR

check if what $m points to is the same as $t

UNDEF

return false, a VALUE is always defined

VALUE

call Switch::Perlish::Smatch::value_cmp() with $t and $m

SEE. ALSO

Switch::Perlish::Smatch

AUTHOR

Dan Brook <cpan@broquaint.com>

COPYRIGHT

Copyright (c) 2005, Dan Brook. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.