new tasks
This commit is contained in:
parent
2a4d27cea0
commit
80737d5a6a
1194 changed files with 15353 additions and 1 deletions
12
Task/Classes/Perl/classes-2.pl
Normal file
12
Task/Classes/Perl/classes-2.pl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
package MyClass;
|
||||
use Moose;
|
||||
|
||||
has 'variable' => (is => 'rw', default => 0);
|
||||
# constructor and accessor methods are added automatically
|
||||
|
||||
sub some_method {
|
||||
my $self = shift;
|
||||
$self->variable(1);
|
||||
}
|
||||
}
|
||||
7
Task/Classes/Perl/classes-3.pl
Normal file
7
Task/Classes/Perl/classes-3.pl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
use MooseX::Declare;
|
||||
class MyClass {
|
||||
has 'variable' => (is => 'rw', default => 0);
|
||||
method some_method {
|
||||
$self->variable(1);
|
||||
}
|
||||
}
|
||||
4
Task/Classes/Perl/classes-4.pl
Normal file
4
Task/Classes/Perl/classes-4.pl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
my $instance = MyClass->new; # invoke constructor method
|
||||
|
||||
$instance->some_method; # invoke method on object instance
|
||||
# instance deallocates when the last reference falls out of scope
|
||||
19
Task/Classes/Perl/classes.pl
Normal file
19
Task/Classes/Perl/classes.pl
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
# a class is a package (i.e. a namespace) with methods in it
|
||||
package MyClass;
|
||||
|
||||
# a constructor is a function that returns a blessed reference
|
||||
sub new {
|
||||
my $class = shift;
|
||||
bless {variable => 0}, $class;
|
||||
# the instance object is a hashref in disguise.
|
||||
# (it can be a ref to anything.)
|
||||
}
|
||||
|
||||
# an instance method is a function that takes an object as first argument.
|
||||
# the -> invocation syntax takes care of that nicely, see Usage paragraph below.
|
||||
sub some_method {
|
||||
my $self = shift;
|
||||
$self->{variable} = 1;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue