The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
use strict;
use warnings FATAL => 'all';

use Test::More;

{
  package BazRole;
  use Web::Simple::Role;

  around dispatch_request => sub {
    my ($orig, $self) = @_;
    return (
      $self->$orig,
      sub (GET + /baz) {
        [ 200,
          [ "Content-type" => "text/plain" ],
          [ 'baz' ],
        ]
      }
    );
  };
}
{
  package FooBar;
  use Web::Simple;
  with 'BazRole';
  sub dispatch_request {
    sub (GET + /foo) {
      [ 200,
        [ "Content-type" => "text/plain" ],
        [ 'foo' ],
      ]
    },
    sub (GET + /bar) {
      [ 200,
        [ "Content-type" => "text/plain" ],
        [ 'bar' ],
      ]
    },
  }
}

use HTTP::Request::Common qw(GET POST);

my $app = FooBar->new;
sub run_request { $app->run_test_request(@_); }

for my $word (qw/ foo bar baz /) {
  my $get = run_request(GET "http://localhost/${word}");
  is($get->content, $word, "Dispatch $word");
}

done_testing;