Module Design and Implementation
accessors. For example, the preceding code uses the heading attribute to hold a ref 
erence to an array. Declaring it as an array creates a more powerful accessor:
package BOA::Probe;
use Class::Struct;
# create accessors and constructor
struct(id       =>  $ ,
       model    =>  $ ,
       contents =>  $ ,
        heading  =>  @ ,
       status   =>  $ );
Now the accessor can accept zero, one, or two parameters. With no parameters, it 
still returns a reference to the array. One parameter is treated as an index into the 
array, and the value is returned. With two parameters, the first is an index and the 
second is the value to be set. So, to reproduce the usage example shown previously, 
the code would now be as follows:
# heading at (10,20,100) at 50 kph
$probe >heading(0, 10);
$probe >heading(1, 20);
$probe >heading(2, 100);
$probe >heading(3, 50);
The result is that loading an array attribute with values becomes more verbose, 
but accessing a single index is simpler. For example, compare these two expressions to 
access the fourth element in the array the speed of the probe:
${$probe >heading()}[3];  # access when heading is a scalar attribute
$probe >heading(3);       # access when heading is an array attribute
The difference is even more pronounced if you change heading to be a hash 
attribute with the keys  x ,  y ,  z , and  speed . Here's the call to struct:
struct(id       =>  $ ,
       model    =>  $ ,
       contents =>  $ ,
        heading  =>  % ,
       status   =>  $ );
89
89






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

web hosting perl

 

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