package TestAnonBefore; use 5.008; use strict; use warnings; use PerlPlusPlus (__PACKAGE__); # ,instance =>'$self'); # $priv_ is optional, $priv_foo is private and will have a private getter/setter for this package only # $priv_foo can also be accessed as '$priv_foo' # # $pub_bar is public and will have a public $self->bar getter/setter # # $prot_baz is protected and will have a $self->bar getter/setter only for subclasses # my($self,$priv_foo,$pub_bar,$prot_baz); # my($self); # can declare $self separately # When sub matches package name, it is constructor # implicit access to $self sub TestAnonBefore { ($pub_bar)=@_; # that's it... } # public instance method, not a getter/setter # getters/setters are generated automatically based on scope (private,protected,public) sub do_stuff : PUBLIC { $self->do_private; 'Private: ' . $self->foo . ' Public: ' . $self->bar . ' Protected: ' . $self->baz; # is equivalent to: 'Private: ' . $priv_foo . ' Public: ' . $pub_bar . ' Protected: ' . $prot_baz; } # sub do_private :Private { sub do_private : PRIVATE { $priv_foo++; } sub stuff{ # same as PUBLIC print "123\n"; } # done declaring a class with PerlPlusPlus no PerlPlusPlus; 1;