FunctionalPerl
view release on metacpan or search on metacpan
docs/howto.md view on Meta::CPAN
`weaken` is a bit more friendly than `$_[0] = undef;` in that it
leaves the variable set if there's still another reference to the head
around.
With this trick (which is used in all of the relevant
functions/methods in `FP::Stream`), the above example actually *does*
release the head of the stream in a timely manner.
Now there may be situations where you actually really want to keep
`$s` alive. In such a case, you can protect its value from being
clobbered by passing it through the `Keep` function from `FP::Weak`:
{
my $s = xfile_lines $path; # lazy linked list of lines
print "# ".$s->first."\n";
Keep($s)->for_each (sub { print "> ".$_[0]."\n" });
$s->for_each (sub { print "again: > ".$_[0]."\n" });
}
Of course this *will* keep the whole file in memory until it reaches
lib/Chj/HTTP/Daemon.pm view on Meta::CPAN
}
}
$r->push_header($key, $val) if $key;
}
my $conn = $r->header('Connection');
if ($proto >= $HTTP_1_1) {
${*$self}{'httpd_nomore'}++ if $conn && lc($conn) =~ /\bclose\b/;
} else {
${*$self}{'httpd_nomore'}++
unless $conn && lc($conn) =~ /\bkeep-alive\b/;
}
if ($only_headers) {
${*$self}{'httpd_rbuf'} = $buf;
return $r;
}
# Find out how much content to read
my $te = $r->header('Transfer-Encoding');
my $ct = $r->header('Content-Type');
lib/Chj/HTTP/Daemon.pm view on Meta::CPAN
# probably OK
} elsif (ref($content) eq "CODE") {
if ($self->proto_ge("HTTP/1.1")) {
$res->push_header("Transfer-Encoding" => "chunked");
$chunked++;
} else {
$self->force_last_request;
}
} elsif (length($content)) {
$res->header("Content-Length" => length($content));
} elsif (lc($res->header('connection') // "") =~ /\bkeep-alive\b/) {
# don't close connection if user asks for it to stay open
} else {
$self->force_last_request;
$res->header('connection', 'close');
}
print $self $res->headers_as_string($CRLF) or die $!;
print $self $CRLF or die $!; # separates headers and content
}
if ($self->head_request) {
( run in 1.762 second using v1.01-cache-2.11-cpan-39bf76dae61 )