KW Perl Mongers Perl Modules: A Look Under the Hood #10

Making an OO Module: Bless

  • 'Blessing' is how you tell perl what class a variable belongs to.

      bless $objref, $class;
  • typically used in a class's new() method.

      package Cards;
      sub new
      {
          my $class = $_[0];
          my $objref = {
                          _suit => $_[1],
                          _name => $_[2]
                       };
          bless $objref, $class;
          return $objref;
      }     

<< Previous | Index | Next >> Copyright © 2004 Daniel Allen