<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    LWP::Protocol::PSGI - Override HTTP/HTTPS backend with your own PSGI
    applciation

SYNOPSIS
      use LWP::UserAgent;
      use LWP::Protocol::PSGI;

      # can be Mojolicious, Catalyst ... any PSGI application
      my $psgi_app = do {
          use Dancer;
          setting apphandler =&gt; 'PSGI';
          get '/search' =&gt; sub {
              return 'googling ' . params-&gt;{q};
          };
          dance;
      };

      LWP::Protocol::PSGI-&gt;register($psgi_app);

      # can hijack any code that uses LWP::UserAgent underneath, with no changes
      my $ua  = LWP::UserAgent-&gt;new;
      my $res = $ua-&gt;get("http://www.google.com/search?q=bar");
      print $res-&gt;content; # "googling bar"

DESCRIPTION
    LWP::Protocol::PSGI is a module to hijack *ANY* code that uses
    LWP::UserAgent underneath such that any HTTP or HTTPS requests can be
    routed to your own PSGI application.

    Because it works with any code that uses LWP, you can override various
    WWW::/Net::/WebService:: modules such as WWW::Mechanize.

      use WWW::Mechanize;
      use LWP::Protocol::PSGI;

      LWP::Protocol::PSGI-&gt;register($my_psgi_app);

      my $mech = WWW::Mechanize-&gt;new;
      $mech-&gt;get("http://amazon.com/"); # $my_psgi_app runs

METHODS
    register
          LWP::Protocol::PSGI-&gt;register($app);
          my $guard = LWP::Protocol::PSGI-&gt;register($app);

        Registers an override hook to hijack HTTP requests. If called in a
        non-void context, returns a Guard object that automatically resets
        the override when it goes out of context.

          {
              my $guard = LWP::Protocol::PSGI-&gt;register($app);
              # code that uses LWP
          }

          # now LWP uses the original HTTP implementations

    unregister
          LWP::Protocol::PSGI-&gt;unregister;

        Resets all the overrides for LWP. If you use the guard interface
        described above, it will be automatically called for you.

AUTHOR
    Tatsuhiko Miyagawa &lt;miyagawa@bulknews.net&gt;

COPYRIGHT
    Copyright 2011- Tatsuhiko Miyagawa

LICENSE
    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

SEE ALSO
    Plack::Client LWP::UserAgent

</pre></body></html>