Perl Module Basics
Now when BOA::Network calls
$logger >write(1, $connection);
the log file will contain a line like the following:
BOA::Network => read 1024 bytes, wrote 58 bytes at 10 kps
Nothing in BOA::Logger changes the overloaded string conversion provides the
method call to BOA::Network::stringify() automatically when BOA::Logger::write()
prints its second argument.
Overloading numification, through the `0+' key, works similarly. Numification
is the name for the process that coverts a variable to a number when the variable is
used in a numeric context. This happens when an object is used with a math
operator, as an array index or in a range operator (..). For example, the variable
$number is numified in the second line in order to increment it:
$foo = "10"; # foo contains the string value "10"
$foo++; # foo is numified and then incremented to contain 11
Overloading numification gives you control over how your variable is represented
as a number.
Finally, a Boolean conversion method, using the bool overload key, is
employed when the object is used in Boolean context. This happens inside an if()
and with logical operations such as && and ||.
Unary Operators
A unary operator is one that applies to only one argument. It's very simple to provide
an overloaded unary operator there are no arguments to deal with and you only
need to worry about implementing the required semantics. See Listing 2 1 for a
module that overrides ++ and so that the object always contains an even number.
51
51
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved