in reply to piggy back infos on a string scalar

Use object overloading.

Ties and Variable::Magic (which was mentioned elsewhere in the thread) attach to the variable, not to the value, like this:

my $x = "Hello world";

attach_some_special_magic( $x );

my $y = $x;

# $y has no special magic

As you're passing the string around, you don't want that. You want an overloaded object.

The danger with overloaded objects is that the third-party module you mention might check !ref( $str ) to ensure it's been passed a string. If it's doing that, you still have one workaround. Bless the object into a package called "0". Then ref( $str ) will return "0" which is false.

Replies are listed 'Best First'.
Re^2: piggy back infos on a string scalar
by LanX (Saint) on Feb 24, 2023 at 16:30 UTC
    > Bless the object into a package called "0". Then ref( $str ) will return "0" which is false.

    LOL. I think the "0" namespace could become quite overloaded now ;-)

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

        well ... at least one (very old) core module is actually using main:: for a part of its functions...

        Cheers Rolf
        (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
        Wikisyntax for the Monastery