Extending Middleware

17 views
Skip to first unread message

yxes

unread,
Feb 23, 2011, 9:29:04 AM2/23/11
to spore...@googlegroups.com
I'm mucking about with Net::HTTP::Spore and I'm having trouble deciding how I should extend it with my own middleware objects.

Specifically, I need an authentication module that is unique to this project and probably not something that should be included in the distro.

When adding a middleware component the command: $mw->extend(OBJECT) is called but it tacks 'Net::HTTP::Spore::Middleware' to the beginning of the call to the object so I can't use my own object as a new Middleware call.  I can't find examples of adding my own middleware outside of the namespace reserved for Spore (if you can point me to these…)

TIA

franck

unread,
Feb 23, 2011, 9:35:05 AM2/23/11
to spore...@googlegroups.com, yxes
Hi
You can write your own middleware (My::Own::Middleware) and when creation a new Net::HTTP::Spore client:

my $client = Net::HTTP::Spore->new_from_spec('spec.json');
$client->enable('+My::Own::Middleware');

If you prefix your middleware name with a '+', it will look outside the N::H::S::Middleware's namespace. And you're right, this is not documented (shame on me).

--

yxes

unread,
Feb 23, 2011, 9:37:16 AM2/23/11
to spore...@googlegroups.com, yxes
That has to be the fastest reply from a developer on an open forum that I've ever had!!!  Thanks!

yxes

unread,
Feb 23, 2011, 4:19:36 PM2/23/11
to SPORE
I know I'm harping on this again… sorry…

I found where you're matching the '+' symbol - should you be stripping
it off of $mw before you pass it on? I'm having errors from
Class::MOP

------------------
in: Net/HTTP/Spore/Role/Middleware.pm

sub _complete_mw_name {
my ($self, $mw) = @_;

if ($mw !~ /(?:^\+|Net\:\:HTTP\:\:Spore\:\:Middleware)/) {
$mw = "Net::HTTP::Spore::Middleware::".$mw;
}

ADD THIS ---> $mw =~ s/\+//; <-------
return $mw;
}
----------------

franck

unread,
Feb 24, 2011, 3:06:23 AM2/24/11
to spore...@googlegroups.com
On Wed, Feb 23, 2011 at 10:19 PM, yxes <yxe...@gmail.com> wrote:
I know I'm harping on this again… sorry…

I found where you're matching the '+' symbol - should you be stripping
it off of $mw before you pass it on?  I'm having errors from
Class::MOP

------------------
in: Net/HTTP/Spore/Role/Middleware.pm

sub _complete_mw_name {
   my ($self, $mw) = @_;

   if ($mw !~ /(?:^\+|Net\:\:HTTP\:\:Spore\:\:Middleware)/) {
       $mw = "Net::HTTP::Spore::Middleware::".$mw;
   }

  ADD THIS ---> $mw =~ s/\+//;  <-------
   return $mw;
}
----------------


you're right, this is an issue ..

I'll do my best to push a new release before saturday, that will fix this. Thanks !
Reply all
Reply to author
Forward
0 new messages