summary refs log tree commit diff
path: root/lib/Net/HTTP/Spore/Middleware.pm
blob: 1b0d5d3ff42f4421da008c4ab9567efd327cc6c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package Net::HTTP::Spore::Middleware;

# ABSTRACT: middlewares base class

use strict;
use warnings;
use Scalar::Util;

sub new {
    my $class = shift;
    bless {@_}, $class;
}

sub response_cb {
    my ($self, $cb) = @_;

    my $body_filter = sub {
        my $filter = $cb->(@_);
    };
    return $body_filter;
}

sub wrap {
    my ($self, $cond, @args) = @_;

    if (!Scalar::Util::blessed($self)) {
        $self = $self->new(@args);
    }

    return sub {
        my $request = shift;
        if ($cond->($request)) {
            $self->call($request, @_);
        }
    };
}

1;