File: README

package info (click to toggle)
liblwp-protocol-psgi-perl 0.02-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 180 kB
  • sloc: perl: 1,369; makefile: 13
file content (77 lines) | stat: -rw-r--r-- 2,330 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
NAME
    LWP::Protocol::PSGI - Override LWP's 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 => 'PSGI';
          get '/search' => sub {
              return 'googling ' . params->{q};
          };
          dance;
      };

      LWP::Protocol::PSGI->register($psgi_app);

      # can hijack any code or module that uses LWP::UserAgent underneath, with no changes
      my $ua  = LWP::UserAgent->new;
      my $res = $ua->get("http://www.google.com/search?q=bar");
      print $res->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::* or WebService::* modules such as WWW::Mechanize, without
    modifying the calling code or its internals.

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

      LWP::Protocol::PSGI->register($my_psgi_app);

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

METHODS
    register
          LWP::Protocol::PSGI->register($app);
          my $guard = LWP::Protocol::PSGI->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->register($app);
              # hijack the code using LWP with $app
          }

          # now LWP uses the original HTTP implementations

    unregister
          LWP::Protocol::PSGI->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 <miyagawa@bulknews.net>

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