summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2017-12-09 16:35:04 +0100
committerYorhel <git@yorhel.nl>2017-12-09 16:35:08 +0100
commitaff3a2174c919da117ae41386dca825910775a36 (patch)
treeec046222b4fd552809be7c8b44b47c8972c2820d /lib
parentba6da0074d4bd7c5e4a557eed2212daeff473148 (diff)
Add a default-exported tuwf() DSL-like function
Another inspiration from Dancer2. While Dancer2 exports a whole bunch of such functions, TUWF's functionality is already mostly contained in a single object, so a single function will do nicely.
Diffstat (limited to 'lib')
-rw-r--r--lib/TUWF.pm7
-rw-r--r--lib/TUWF.pod16
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/TUWF.pm b/lib/TUWF.pm
index 109f19c..4ea7e71 100644
--- a/lib/TUWF.pm
+++ b/lib/TUWF.pm
@@ -76,9 +76,11 @@ my @handlers;
sub import {
my $self = shift;
my $pack = caller();
+ # Always export 'tuwf'. This can still be excluded with a '!tuwf' in @_
+ my @arg = ('tuwf', @_);
# import requested functions from TUWF submodules
- croak $@ if @_ && !eval "package $pack; import TUWF::func \@_; 1";
+ croak $@ if !eval "package $pack; import TUWF::func \@arg; 1";
}
@@ -224,6 +226,9 @@ our @EXPORT_OK = (
@TUWF::XML::EXPORT_OK
);
our %EXPORT_TAGS = %TUWF::XML::EXPORT_TAGS;
+our @EXPORT = ('tuwf');
+
+sub tuwf() { $TUWF::OBJ }
diff --git a/lib/TUWF.pod b/lib/TUWF.pod
index d269a16..e66f338 100644
--- a/lib/TUWF.pod
+++ b/lib/TUWF.pod
@@ -210,6 +210,22 @@ approach does not suffer from this problem and is therefore recommended.
+=head1 EXPORTED FUNCTIONS
+
+By default, TUWF exports a single function.
+
+=head2 tuwf()
+
+Returns the global TUWF object. This allows for convenient DSL-like access to
+methods in the TUWF object:
+
+ # Get the client IP:
+ my $remote_ip = tuwf->reqIP;
+
+ # Send a 404 response:
+ tuwf->resNotFound;
+
+
=head1 GLOBAL FUNCTIONS