Skip to content

Commit

Permalink
Move into separate files again
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed May 29, 2022
1 parent 8c94e8c commit bf1d66f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 42 deletions.
4 changes: 4 additions & 0 deletions Changes
@@ -1,6 +1,10 @@
Revision history for HTTP-Roles

{{$NEXT}}
- Restore separate files for the separate use targets again, as
the single file way appears to have broken some client's test
code, specifically HTTP::Server::Async.
- Follow the name change of the repository.

0.2.1 2022-05-28T22:34:12+02:00
- Changed the name of the module to HTTP::Roles, not just in
Expand Down
8 changes: 4 additions & 4 deletions META6.json
Expand Up @@ -14,10 +14,10 @@
"name": "HTTP::Roles",
"perl": "6.*",
"provides": {
"HTTP::Request::Role": "lib/HTTP/Roles.rakumod",
"HTTP::Response::Role": "lib/HTTP/Roles.rakumod",
"HTTP::Request::Role": "lib/HTTP/Request/Role.rakumod",
"HTTP::Response::Role": "lib/HTTP/Response/Role.rakumod",
"HTTP::Roles": "lib/HTTP/Roles.rakumod",
"HTTP::Server::Role": "lib/HTTP/Roles.rakumod"
"HTTP::Server::Role": "lib/HTTP/Server/Role.rakumod"
},
"resources": [
],
Expand All @@ -26,5 +26,5 @@
],
"test-depends": [
],
"version": "0.2.1"
"version": "0.2.2"
}
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
[![Actions Status](https://github.com/raku-community-modules/HTTP-Server/actions/workflows/test.yml/badge.svg)](https://github.com/raku-community-modules/HTTP-Server/actions)
[![Actions Status](https://github.com/raku-community-modules/HTTP-Roles/actions/workflows/test.yml/badge.svg)](https://github.com/raku-community-modules/HTTP-Roles/actions)

NAME
====
Expand Down
19 changes: 19 additions & 0 deletions lib/HTTP/Request/Role.rakumod
@@ -0,0 +1,19 @@
role HTTP::Request::Role {
has Str $.method;
has Str $.uri;
has Str $.version;
has Buf $.data is rw;
has %.params;
has %.headers;

method header(*@headers) {
my @r;
my %h = @headers.map({ $_.lc => $_ });
%.headers.keys.map(-> $k {
@r.append($( %h{$k.lc} => %.headers{$k} )) if $k.lc ~~ any %h.keys;
});
@r
}
}

# vim: expandtab shiftwidth=4
14 changes: 14 additions & 0 deletions lib/HTTP/Response/Role.rakumod
@@ -0,0 +1,14 @@
use HTTP::Status;
BEGIN my %status := HTTP::Status.Map;

role HTTP::Response::Role {
has Int:D $.status is rw = 200;
has %.headers is rw;
has $.connection;
has %.statuscodes = %status;

method close($data?, :$force? = False) {*}
method write($data) {*}
}

# vim: expandtab shiftwidth=4
40 changes: 3 additions & 37 deletions lib/HTTP/Roles.rakumod
@@ -1,40 +1,6 @@
use HTTP::Status;
BEGIN my %status := HTTP::Status.Map;

role HTTP::Server::Role {
method handler(Callable $sub) {*} # to be called when request is complete
method middleware(Callable $sub) {*} # to be called when headers are complete
method after(Callable $sub) {*} # to be called when response is complete
method listen() {*} # to be called to start the server
}

role HTTP::Request::Role {
has Str $.method;
has Str $.uri;
has Str $.version;
has Buf $.data is rw;
has %.params;
has %.headers;

method header(*@headers) {
my @r;
my %h = @headers.map({ $_.lc => $_ });
%.headers.keys.map(-> $k {
@r.append($( %h{$k.lc} => %.headers{$k} )) if $k.lc ~~ any %h.keys;
});
@r
}
}

role HTTP::Response::Role {
has Int:D $.status is rw = 200;
has %.headers is rw;
has $.connection;
has %.statuscodes = %status;

method close($data?, :$force? = False) {*}
method write($data) {*}
}
use HTTP::Server::Role;
use HTTP::Request::Role;
use HTTP::Response::Role;

=begin pod
Expand Down
8 changes: 8 additions & 0 deletions lib/HTTP/Server/Role.rakumod
@@ -0,0 +1,8 @@
role HTTP::Server::Role {
method handler(Callable $sub) {*} # to be called when request is complete
method middleware(Callable $sub) {*} # to be called when headers are complete
method after(Callable $sub) {*} # to be called when response is complete
method listen() {*} # to be called to start the server
}

# vim: expandtab shiftwidth=4

0 comments on commit bf1d66f

Please sign in to comment.