I use a variable which have a method overload to string in regex replace.

the result is string only if match success. I thought it should be always
string.

Could anyone explain how this happen? Thanks.

Below is the code

use Text::Xslate::Type::Raw; # a wraper of string, provide as_string, which
is overloaded to string, return the string.

use DDP;


sub strip_x { return $_[0]=~s/x//gr }


my $raw_a = Text::Xslate::Type::Raw->new("aaaaa");

p $raw_a;

my $striped_a = strip_x($raw_a);

p $striped_a;


my $raw_b = Text::Xslate::Type::Raw->new("bbbbx");

p $raw_b;

$striped_b = strip_x($raw_b);

p $striped_b;


__END__


Text::Xslate::Type::Raw  {

  public methods (3) : (), as_string, new

    private methods (0)

  internals: "aaaaa"

}

Text::Xslate::Type::Raw  {

    public methods (3) : (), as_string, new

      private methods (0)

    internals: "aaaaa"

}

Text::Xslate::Type::Raw  {

    public methods (3) : (), as_string, new

      private methods (0)

    internals: "bbbbx"

}

"bbbb"

Reply via email to