diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..2071b23 --- /dev/null +++ b/COPYING @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/FU.pm b/FU.pm index ca313ff..2fc0234 100644 --- a/FU.pm +++ b/FU.pm @@ -4,22 +4,14 @@ use Carp 'confess', 'croak'; use IO::Socket; use POSIX; use FU::Util; -use FU::XMLWriter; -my %export_funcs = do { no strict 'refs'; +( - (map +($_, \*{'FU::Util::'.$_}), @FU::Util::EXPORT_OK), - (map +($_, \*{'FU::XMLWriter::'.$_}), @FU::XMLWriter::EXPORT_OK), -) }; -my %export_tags = %FU::XMLWriter::EXPORT_TAGS; - sub import($pkg, @opt) { my $c = caller; no strict 'refs'; *{$c.'::fu'} = \&fu; - for (map /^:(.+)$/ && $export_tags{$1} ? $export_tags{$1}->@* : ($_), @opt) { + for (@opt) { if ($_ eq '-spawn') { _spawn() } - elsif ($export_funcs{$_}) { *{$c.'::'.$_} = $export_funcs{$_} } else { croak "Unknown import option: '$_'" } } } @@ -276,10 +268,7 @@ sub _log_err($e) { } sub _do_req($c) { - local $REQ = { - hdr => {}, - xml => FU::XMLWriter::_new(), - }; + local $REQ = { hdr => {} }; local $fu = bless {}, 'FU::obj'; $REQ->{ip} = $c->{client_sock} isa 'IO::Socket::INET' ? $c->{client_sock}->peerhost : '127.0.0.1'; @@ -588,10 +577,7 @@ sub done { die bless [200,'Done'], 'FU::err' } sub error($,$code,$msg=$code) { die bless [$code,$msg], 'FU::err' } sub status($, $code) { $FU::REQ->{status} = $code } -sub set_body($, $data) { - $FU::REQ->{xml}->_done; - $FU::REQ->{resbody} = $data; -} +sub set_body($, $data) { $FU::REQ->{resbody} = $data } sub reset { fu->status(200); @@ -650,16 +636,14 @@ sub _finalize { state $haszstd = eval { require Compress::Zstd; 1 }; my $r = $FU::REQ; - my $xml = $r->{xml}->_done; - $r->{resbody} = $xml if length $xml; - if ($r->{status} == 204) { delete $r->{reshdr}{'content-length'}; delete $r->{reshdr}{'content-encoding'}; $r->{resbody} = ''; } else { - if (($haszlib || $haszstd) && !defined $r->{reshdr}{'content-encoding'} && FU::compress_mimes->{$r->{reshdr}{'content-type'}}) { + if (($haszlib || $haszstd) && length($r->{resbody}) > 256 + && !defined $r->{reshdr}{'content-encoding'} && FU::compress_mimes->{$r->{reshdr}{'content-type'}}) { $r->{reshdr}{'vary'} = ($r->{reshdr}{'vary'} ? $r->{reshdr}{'vary'}.', ' : '').'accept-encoding' if ($r->{reshdr}{'vary'}||'') !~ /accept-encoding/i; @@ -729,10 +713,22 @@ FU - Framework Ultimatum: A Lean and Efficient Zero-Dependency Web Framework. =head1 SYNOPSIS use v5.36; - use FU -spawn, ':html5_'; + use FU -spawn; + use FU::XMLWriter ':html5_'; + + sub myhtml_($title, $body) { + fu->set_body(html_ sub { + head_ sub { + title_ $title; + }; + body_ $body; + }); + } FU::get qr{/hello/(.+)}, sub($who) { - h1_ "Hello, $who!"; + my_html_ "Website title", sub { + h1_ "Hello, $who!"; + }; }; FU::run; @@ -758,7 +754,17 @@ standalone and can be used independently of the framework: Note that everything in this distribution requires a moderately recent version of Perl (5.36+), a C compiler and a 64-bit POSIXy system (not Windows, that -is). +is). There are a few additional optional dependencies: + +=over + +=item * C - required for L, dynamically loaded through +C. + +=item * L - to support transparent HTTP compression through +Zstandard. + +=back =head2 Framework Overview @@ -794,27 +800,8 @@ certainly not great if you plan to transfer large files. =back -=head2 Importing FU - -You'll usually want to add the following statement somewhere near the top of -your script: - - use FU -spawn; - -The C<-spawn> option tells C to read running configuration from environment -variables and command-line arguments during early startup, see L below. - -C additionally re-exports all tags and functions from L and -L, so you can shorten your C statements: - - use FU -spawn, 'json_format', ':html5_'; - -Is equivalent to: - - use FU -spawn; - use FU::Util 'json_format'; - use FU::XMLWriter ':html5_'; +The rest of this document is reference documentation; there's no easy +introductionary cookbook-style docs yet, sorry about that. =head2 Framework Configuration @@ -983,3 +970,11 @@ their code. In both modes, C or C can be used to trigger a clean shutdown. I Alternate FastCGI spawning options & server config examples. + +=head1 COPYRIGHT + +MIT. + +=head1 AUTHOR + +Yorhel diff --git a/FU/Pg.pm b/FU/Pg.pm index fd275c0..dc7b037 100644 --- a/FU/Pg.pm +++ b/FU/Pg.pm @@ -522,3 +522,11 @@ Popular DBI wrapper with some API conveniences. I may have taken some inspiration from it in the design of this module's API. =back + +=head1 COPYRIGHT + +MIT. + +=head1 AUTHOR + +Yorhel diff --git a/FU/Util.pm b/FU/Util.pm index f56d6a4..4d88519 100644 --- a/FU/Util.pm +++ b/FU/Util.pm @@ -312,3 +312,11 @@ for more weirdness and edge cases. See also L for a more portable solution, although that one does not support passing along regular data. + +=head1 COPYRIGHT + +MIT. + +=head1 AUTHOR + +Yorhel diff --git a/FU/XMLWriter.pm b/FU/XMLWriter.pm index 5d27e04..9c6fd64 100644 --- a/FU/XMLWriter.pm +++ b/FU/XMLWriter.pm @@ -289,3 +289,11 @@ L, but its syntax isn't quite as nice. And there's also L, L, L and many more modules on CPAN. In fact I don't know why you should use this module instead of whatever is available on CPAN. + +=head1 COPYRIGHT + +MIT. + +=head1 AUTHOR + +Yorhel diff --git a/README.md b/README.md index 0db5808..42b4bc6 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,12 @@ make install Things that may or may not happen: -- FU - The website framework, taking inspiration from TUWF. - FU::JSON - JSON::{XS,PP,etc}-compatible wrapper around FU::Util's JSON functions? I prolly won't need this myself, but could be handy. +- FU::DBI - DBI wrapper with a FU::Pg-like API, for easier integration into FU. - FU::Log - Basic logger. - FU::Validate - TUWF::Validate & normalization with some improvements. - FU::Mailer - Simple sendmail wrapper + +# License + +MIT.