Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Blessables -- What Can You Make Into Objects?

by demerphq (Chancellor)
on Apr 26, 2002 at 20:57 UTC ( [id://162397]=note: print w/replies, xml ) Need Help??


in reply to Blessables -- What Can You Make Into Objects?

In your tutorial you mention blessing a precompiled regex.
my $self = qr/\[$word\]/; bless($self, $class);
My question is how does one then (cleanly) determine that the object is indeed a blessed precompiled regex?

Oh and I already asked on p5p without much results and also here at the monastery

Cheers,

Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.

Replies are listed 'Best First'.
Re: Re: Blessables -- What Can You Make Into Objects?
by Anonymous Monk on Apr 26, 2002 at 21:59 UTC
    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" ...

      Actually stringifying a regex does not return a string that contains "Regexp". It will look like any other scalar reference that has been stringified. (Youre thinking of what ref() would return.)

      Thats part of the problem...

      :-)

      Yves / DeMerphq
      ---
      Writing a good benchmark isnt as easy as it might look.

        But that's why I overloaded stringification to contain 'Regexp' instead of 'SCALAR', because we still want ref() to return the classname and we want some way to determine of our blessed object is a Regexp type right?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://162397]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-20 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found