# Object Oriented Perl Chap03

This is a note about chap03 in “Object oriented perl”.

1.In object oriented perl, there are three rules,

2.Some cases while calling a method through an arrow:

3.When a method like Bug::print_me is called, the argument list that it receives begins with the object reference through which it was called, followed by any arguments that were explicitly given to the method. That means that calling

is not the same as calling

In the first case, print_me is treated as a regular subroutine so the argument list passed to Bug::print_me is equivalent to:

In the second case, print_me is treated as a method so the argument list is equivalent to:

Having a reference to the object passed as the first parameter is vital, because it means that the method then has access to the object on which it’s supposed to operate. Hence you’ll find that most methods in Perl start with something equivalent to this:

or better still:

This second version is better because it provides a lexically scoped copy of the argument list (@args).

4.Unlike other object-oriented languages, Perl doesn’t require that an object be a special kind of recordlike data structure. In fact, you can use any existing type of Perl variable—a scalar, an array, a hash—as an object in Perl.

5.The bless function takes two arguments: a reference to the variable to be marked and a string containing the name of the class. It then sets an internal flag on the variable, indicating that it now belongs to the class.

6.We didn’t bless the reference; we blessed the referent. The scalar didn’t change—only the nameless hash it refers to has been marked.

7.You can check that the blessing succeeded by applying the built-in ref function to \$nextbug. Normally, when ref is applied to a reference, it returns the type of that reference.

THe above code gives out the result, Bug.

8.Based on the things we said above, we will show a piece of code to demonstrate how to get and set attributes in perl.