in reply to Re: overload::constant passes fragments, not whole strings under interpolation. Help?
in thread overload::constant passes fragments, not whole strings under interpolation. Help?
That's great. Here's the outline for code that does exactly that. It passes a postponing object to overload::constant, postpones any concatenation and then runs the actual conversion function on stringification at the end.
package My::Package; use strict; use warnings; sub convert { YOUR CODE GOES HERE } use overload( '.' => \ &_concat, '""' => \ &_finalize ); sub import { overload::constant qr => \ &_postpone; } sub _postpone { my $re = shift; bless \ $re, __PACKAGE__; } sub _concat { my ( $a, $b, $inverted ) = @_; ($a,$b)=($b,$a) if $inverted; $a = $$a if ref( $a ) eq __PACKAGE__; $b = $$b if ref( $b ) eq __PACKAGE__; my $re = "$a$b"; bless \ $re, __PACKAGE__; } sub _finalize { @_ = ${shift()}; &convert; } 1;
|
|---|