You want to buy The Damian == 'Damian Conway' book on Object Oriented Perl - Google for same. Damian is a Perl guru and comes from C++ Here is short closure example of a private var, and private func:
# here $count and $private_func are undef # add_to_count() sub_from_count() get_count() set_count() and widget() # are the only ways to access $count and ($)private_func() { # use a closure to keep peoples sticky fingers off $count my $count; # define a func totally private to this closure my $private_func = sub { [blah blah blah] } # now here are a couple of modifiers sub add_to_count { ++$count } sub sub_from_count { --$count } # and the usual couple of accessors.... sub get_count { $count } sub set_count { my ($new_count, $user ) = @_; if ( $user = 'root' ) { # OK, OK so it is a silly example! $count = $new_count; return $count; } else { warn "Only root can set count directly, use add/sub/get bl +ah..." return undef; } } # and something silly to use our private func... sub widget { &$private_func(@_) if $moon_in_venus && $believe_that_sort of +stuff; } } # here $count and $private_func are undef
This shows you how to make a private var and use it but you can make private funcs as well using the syntax shown. Only stuff in the closure (block) can use it using syntax &$privat_func(@args). Note a perl func returns the last val evaluated so you can often neglect the return as it is imlicit.
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: characterstics of private in perl
by tachyon
in thread characterstics of private in perl
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |