Permalink
Browse files

trivial importing example

  • Loading branch information...
1 parent 78f3e2a commit 596555432942226c9ec0b939272a776898723c43 @moritz moritz committed Apr 30, 2012
Showing with 14 additions and 2 deletions.
  1. +14 −2 src/subs-n-sigs.pod
View
@@ -93,11 +93,23 @@ C<our> also makes subroutines visible from the outside of a package or module:
=end programlisting
-# TODO: elaborate
-
You may also export a subroutine to make it available to another
scope.
+ # in file Math/Trivial.pm
+ # TODO: find a better example
+ # TODO: explain modules, search paths
+ module Math::Trivial {
+ sub double($x) is export {
+ return 2 * $x;
+ }
+ }
+
+then in a different program or module you can write
+
+ use Math::Trivial; # imports sub double
+ say double(21); # 21 is only half the truth
+
X<anonymous subroutines>
X<subroutines, anonymous>
X<subroutines, first-class>

0 comments on commit 5965554

Please sign in to comment.