Created
November 20, 2008 23:10
-
-
Save masak/27262 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$ cat lingering-named-parameter.p6 | |
use v6; | |
class A { | |
sub format_line($line is rw, :$link_maker) { | |
my $result = $line; | |
if defined $link_maker { | |
my $link_regex = / \[\[ (<-[\]]>+) \]\] /; # / | |
while $result ~~ $link_regex { | |
$result .= subst( $link_regex, { $link_maker($0) } ); | |
} | |
} | |
return $result; | |
} | |
sub format_paragraph($paragraph, :$link_maker) { | |
return map { format_line($^line, :$link_maker) }, | |
$paragraph.split("\n"); | |
} | |
method format($text, :$link_maker) { | |
return format_paragraph($text, :$link_maker); | |
} | |
} | |
say A.new.format("a [[link]], sir", { "TROGDOR!" }); | |
say A.new.format("a [[link]], sir") # look, no closure | |
$ perl6 lingering-named-parameter.p6 | |
a TROGDOR!, sir | |
a TROGDOR!, sir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment