Blessing is the usual technique for creating all objects. All it does is mark the 'thingy' (scalar, hash or whatever) pointed to by the reference as belonging to a particular package.
Doing this allows the method call syntax to work, ie
$ref->method(@args)
is shorthand to tell perl to execute
Foo::Bar::method($ref, @args)
where Foo::Bar is the package that the thingy pointed to
by $ref has been blessed into. If the 'method' sub doesn't
exist in Foo::Bar, then Perl looks in the packages listed in @Foo::Bar::ISA for a sub called 'method', and so on.
Tying is something completely unrelated, and only has a marginal conection with OO (in the sense that it's implemented using OO). It's used when you want to take control of how a variable is accessed.
tie @arr, Foo::Bar, @args
calls
Foo::Bar->TIEARRAY(@args)
and this sub is supposed to return a blessed object of
some type (not necessarily an array). Perl then attaches
this object to the variable in question (@arr), and marks
it as being tied. Any subsequent access of this variable
(eg $arr[3] = 4) is intercepted, and rather than
modifying the contents of the real array, a method is called on its associated object, eg
$hidden_object->STORE(3,4);
Dave. |