Search code examples
regexperlmoose

How do I use a Moose Type as a regex match expression?


I have the following type in my class file:

has 'cardNumber' => (is => 'ro', isa => 'Int', required => 1);

I am trying to do the following:

foreach $_ (@accountsInfo) {
      if ($_ =~ m/^$self->cardNumber()/) {
            $self->pushing(split(/,/, $_));
            $self->invokeAccount();
      }
 }

But I can't get it to test properly. If I manually type in the number I am looking for in the regex slashes it works perfectly. Can you please help me to use the cardNumber Type?


Solution

  • Print it to see what you're trying to match. You'll get output like SOMECLASS=HASH(0x6bbb48)->foo(). A solution:

    /^@{[$self->cardNumber()]}/