0

I don't know How bless operator works? How it associated the given reference with class.It returns the reference.

In that we can call the method using its returned reference and passed reference also.In this function which is object. I want to know the meaning of the term 'bless'.

xxfelixxx
  • 6,318
  • 3
  • 30
  • 38
vaishali
  • 335
  • 1
  • 10

2 Answers2

4

When I'm running training courses, I tell people that bless() is like taking a post-it note, writing the name of the class on it and sticking the note on the forehead of the hash reference.

The hash reference isn't changed in any way. It just has access to this one extra piece of information - the name of the class that it belongs to.

Does that help at all?

Dave Cross
  • 65,668
  • 3
  • 47
  • 91
  • 1
    Except that it is the *object* of the reference that gets the sticky note, not the reference itself. It's done that way only so that `bless` has to cope with just a scalar parameter. If I have `my %obj; bless \%obj, 'Class';` I can then write `print ref \%obj;` and get `Class` – Borodin Jul 07 '16 at 16:05
0

From the source: Bless My Referents

Once an object is blessed, ref returns the name of its class instead. So after the blessing, ref($nextbug) will return 'Bug'. Of course the object itself still is a hash, but now it's a hash that belongs to the Bug class. The various entries of the hash become the attributes of the newly created Bug object.

enter image description here

Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319