Created
February 14, 2014 11:26
-
-
Save dolmen/8999556 to your computer and use it in GitHub Desktop.
Exemple de méthode vraiment privée en Perl.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
no warnings 'experimental'; | |
use feature 'lexical_subs'; # my sub, experimental in perl 5.18 | |
use feature 'say'; | |
use utf8; | |
package AA; | |
sub new | |
{ | |
bless \(my $nom = $_[1]), ref($_[0]) || $_[0] | |
} | |
my sub privée_5_18 | |
{ | |
my $self = shift; | |
say "Méthode privée_5_18 appellée depuis ${$self} !"; | |
} | |
my $privée = sub | |
{ | |
my $self = shift; | |
say "Méthode privée appellée depuis ${$self} !"; | |
}; | |
sub public | |
{ | |
my $self = shift; | |
say 'Méthode publique appellée !'; | |
$self->$privée(); | |
# $self->privée_5_18(); => ne marche pas | |
privée_5_18($self); | |
} | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Term::Encoding; | |
use open ':std', ':encoding(' . Term::Encoding::term_encoding() . ')'; | |
use AA; | |
AA->new('Toto')->public; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment