-
Notifications
You must be signed in to change notification settings - Fork 630
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--sort=no | ||
--fields=+lK |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
foo input.pl /^fun foo($x, $y, $z = 5) {$/;" fun language:FunctionParameters | ||
bar input.pl /^method bar($label, $n) {$/;" method language:FunctionParameters | ||
create_point input.pl /^fun create_point(:$x, :$y, :$color) {$/;" fun language:FunctionParameters | ||
Derived input.pl /^package Derived {$/;" package language:Perl | ||
Derived input.pl /^package Derived {$/;" class language:Moose | ||
go_big input.pl /^ has 'go_big' => ($/;" attribute language:Moose class:Derived |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Taken from https://metacpan.org/pod/Function::Parameters | ||
use Function::Parameters; | ||
|
||
# plain function | ||
fun foo($x, $y, $z = 5) { | ||
return $x + $y + $z; | ||
} | ||
print foo(1, 2), "\n"; # 8 | ||
|
||
# method with implicit $self | ||
method bar($label, $n) { | ||
return "$label: " . ($n * $self->scale); | ||
} | ||
|
||
# named arguments: order doesn't matter in the call | ||
fun create_point(:$x, :$y, :$color) { | ||
print "creating a $color point at ($x, $y)\n"; | ||
} | ||
create_point( | ||
color => "red", | ||
x => 10, | ||
y => 5, | ||
); | ||
|
||
package Derived { | ||
use Function::Parameters qw(:std :modifiers); | ||
use Moo; | ||
|
||
extends 'Base'; | ||
|
||
has 'go_big' => ( | ||
is => 'ro', | ||
); | ||
|
||
# "around" method with implicit $orig and $self | ||
around size() { | ||
return $self->$orig() * 2 if $self->go_big; | ||
return $self->$orig(); | ||
} | ||
} |