#!/usr/bin/env perl use v5.18; use feature qw(lexical_subs); no warnings qw(experimental); package MyClass { # # Private methods # my sub get_number { my $self = shift; return $self->{number}; } # # Public methods # sub new { my $class = shift; return bless {@_}, $class; } sub say_number { my $self = shift; # Slightly funky syntax for calling a # lexical sub as a private method... say $self->${ \\&get_number }; } } package ChildClass { use base "MyClass"; # # A public method that has the same name as a # private method in the superclass. Note that # the private method will *NOT* get overridden! # Yay! # sub get_number { warn "You're not allowed to get the number!"; } } my $o = ChildClass->new(number => 42); $o->say_number; # works... my $p = MyClass->new(number => 666); $p->get_number; # asplode; it's a private method #### my $private_method = sub { ...; }; $self->$private_method(@args);