How do I make private functions in a Perl module?

前端 未结 9 961
后悔当初
后悔当初 2020-12-23 20:43

I am working on a little Perl module and for some reason I had the test driver script that was using my new module call one of the functions that I thought would be private,

9条回答
  •  悲&欢浪女
    2020-12-23 21:02

    This works:

    my $priv_func1 = sub {
        my $self = shift; say 'func1';
    };
    
    sub public_sub { 
        my $self = shift;
    
        $self->$priv_func1(@_);
    }
    

提交回复
热议问题