in reply to Re: Blessables -- What Can You Make Into Objects?
in thread Blessables -- What Can You Make Into Objects?
You could overload stringification in your object that blesses
the regexp.
package Blessed::Re; use overload q{""} => 'stringify'; sub new { my $class = shift; my $word = shift; my $self = qr/\[$word\]/; return bless $self, $class; } sub stringify { my $self = shift; my $string = overload::StrVal $self; $string =~ s/SCALAR/Regexp/; return $string; } package main; my $x = Blessed::Re->new('word'); print "Class: ",ref $x,"\n"; print "Type: ", $x =~ /=(\w+)\(/, "\n";
On the other hand, you did say "cleanly" ...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Blessables -- What Can You Make Into Objects?
by demerphq (Chancellor) on Apr 26, 2002 at 22:06 UTC | |
by Anonymous Monk on Apr 26, 2002 at 22:14 UTC | |
by demerphq (Chancellor) on Apr 26, 2002 at 22:24 UTC |
In Section
Tutorials