Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Singleton/Perl/singleton.pl
Normal file
29
Task/Singleton/Perl/singleton.pl
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package Singleton;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $Instance;
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
$Instance ||= bless {}, $class; # initialised once only
|
||||
}
|
||||
|
||||
sub name {
|
||||
my $self = shift;
|
||||
$self->{name};
|
||||
}
|
||||
|
||||
sub set_name {
|
||||
my ($self, $name) = @_;
|
||||
$self->{name} = $name;
|
||||
}
|
||||
|
||||
package main;
|
||||
|
||||
my $s1 = Singleton->new;
|
||||
$s1->set_name('Bob');
|
||||
printf "name: %s, ref: %s\n", $s1->name, $s1;
|
||||
|
||||
my $s2 = Singleton->new;
|
||||
printf "name: %s, ref: %s\n", $s2->name, $s2;
|
||||
Loading…
Add table
Add a link
Reference in a new issue