Skip to content

Commit

Permalink
add perl version template pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
oxnz committed Feb 12, 2014
1 parent 46a8e6b commit cdc3632
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ command | [DONE](./src/command/command.md) | [DONE](./src/command/cpp) | [DONE](
decorator | [DONE](./src/decorator/decorator.md) | [DONE](./src/decorator/cpp) | [DONE](./src/decorator/java) | [DONE](./src/decorator/python) | [DONE](./src/decorator/php) | [DONE](./src/decorator/perl)
facade | [DONE](./src/facade/facade.md) | [DONE](./src/facade/cpp) | [DONE](./src/facade/java) | [DONE](./src/facade/python) | [DONE](./src/facade/php) | [DONE](./src/facade/perl)
observer | [DONE](./src/observer/observer.md) | [DONE](./src/observer/cpp) | [DONE](./src/observer/java) | [DONE](./src/observer/python) | [DONE](./src/observer/php) | [DONE](./src/observer/perl)
template | [DONE](./src/template/template.md) | [DONE](./src/template/cpp) | [DONE](./src/template/java) | [DONE](./src/template/python) | [DONE](./src/template/php)
template | [DONE](./src/template/template.md) | [DONE](./src/template/cpp) | [DONE](./src/template/java) | [DONE](./src/template/python) | [DONE](./src/template/php) | [DONE](./src/template/perl)
adapter | [DONE](./src/adapter/adapter.md) | [DONE](./src/adapter/cpp) | [DONE](./src/adapter/java) | [DONE](./src/adapter/python) | [DONE](./src/adapter/php) | [DONE](./src/adapter/perl)
flyweight | [DONE](./src/flyweight/flyweight.md) | [DONE](./src/flyweight/cpp) | [DONE](./src/flyweight/java) | [DONE](./src/flyweight/python) | [DONE](./src/flyweight/php)
bridge | [DONE](./src/bridge/bridge.md) | [DONE](./src/bridge/cpp) | [DONE](./src/bridge/java) | [DONE](./src/bridge/python) | [DONE](./src/bridge/php) | [DONE](./src/bridge/perl)
Expand Down
25 changes: 25 additions & 0 deletions src/template/perl/AbstractClass.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package AbstractClass;

use strict;
use warnings;

sub new {
my ($class, $args) = @_;
return bless {}, $class;
}

sub templateMethod {
my $self = shift;
$self->primitiveOperation1;
$self->primitiveOperation2;
}

sub primitiveOperation1 {
die "ABSTRACT CLASS METHOD CANNOT BE CALLED DIRECTLY\n";
}

sub primitiveOperation2 {
die "ABSTRACT CLASS METHOD CANNOT BE CALLED DIRECTLY\n";
}

1;
21 changes: 21 additions & 0 deletions src/template/perl/AbstractClass/ConcreteClass.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package AbstractClass::ConcreteClass;
use parent AbstractClass;

use strict;
use warnings;

sub new {
my ($class, $args) = @_;
my $self = {};
return bless $self, $class;
}

sub primitiveOperation1 {
print "-->", (caller(0))[3], "\n";
}

sub primitiveOperation2 {
print "-->", (caller(0))[3], "\n";
}

1;
11 changes: 11 additions & 0 deletions src/template/perl/test.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env perl
# auther: oxnz
# coding: utf-8

use strict;
use warnings;

use AbstractClass::ConcreteClass;

my $cls = AbstractClass::ConcreteClass->new;
$cls->templateMethod;

0 comments on commit cdc3632

Please sign in to comment.