Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Modules > Creating Modules - Pg. 415

Example 17-3. Objects instead of accessor subroutines (continued) # Any non-negative depth is okay... if ($new_depth >= 0) { $depth_of{ident $self} = $new_depth; } # Any negative depth is an error, so fix it and report... else { $depth_of{ident $self} = 0; carp "Negative depth ($new_depth) interpreted as zero"; } return; } # Method to serialize a data structure, passed by reference... sub freeze { my ($self, $data_structure_ref) = @_; my $compactor = $compactor{$compaction_of{ident $self}}; return $compactor->( _serialize($data_structure_ref) ); } # etc. } # and elsewhere...