Mangling
Upcoming SlideShare
Loading in...5
×
 

Mangling

on

  • 4,191 views

 

Statistics

Views

Total Views
4,191
Views on SlideShare
4,189
Embed Views
2

Actions

Likes
3
Downloads
4
Comments
0

2 Embeds 2

https://duckduckgo.com 1
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Mangling Mangling Presentation Transcript

  • Mangling CPAN with Plack::App::Proxy Olaf Alders Toronto Perl Mongers September 30, 2010 [email_address] twitter.com/wundercounter
  • What is PSGI/Plack? “ Superglue interface between perl web application frameworks and web servers, just like Perl is the duct tape of the internet. PSGI is an interface between Perl web applications and web servers, and Plack is a Perl module and toolkit that contains PSGI middleware, helpers and adapters to web servers. PSGI and Plack are inspired by Python's WSGI and Ruby's Rack.” http://plackperl.org
  • Plack::App::Proxy Plack middleware which allows you to map a local url to another local (or remote) url.
    • Easier to set up than Apache's mod_proxy
    • Doesn't require Apache
    • Doesn't appear to have the same security implications
  • How can we (ab)use this?
    • search.cpan.org is a great resource
    • I wish it had syntax highlighting
    • I don't want to use a Firefox plugin (Greasemonkey)
    • Using Plack, I will subvert CPAN to my will
    • I have also enlisted @ioncache to help me out
  • Introducing cpan-mangler http://github.com/oalders/cpan-mangler
  • Install and Run git clone http://github.com/ioncache/Plack-Middleware-HTMLify.git git clone http://github.com/oalders/cpan-mangler.git cpanm Plack Plack::App::Proxy cd cpan-mangler plackup -I../Plack-Middleware-HTMLify/lib
  • Documentation before:
  •  
  • Documentation after:
  •  
  • Is there more?
    • POD now looks much better
    • How about the module source?
  • Module source before:
  •  
  • Module source after:
  •  
  • Looking under the hood Let's look at how we went about setting up the proxy. It's very easy to set up. You can proxy a site of your choice in just a few minutes.
  • Set up the proxy use Plack::App::Proxy; use Plack::Builder; my $app = builder { mount "/" => builder {; Plack::App::Proxy->new( remote => 'http://search.cpan.org/' )->to_app; }; }; $app; # http://github.com/oalders/cpan-mangler/blob/master/examples/proxy.psgi
  • Mangle the POD use Plack::App::Proxy; use Plack::Builder; my $pod_highlight = q[...]; # insert JavaScript and CSS here my $app = builder { enable &quot;Debug&quot;, panels => [qw(Environment Memory Timer Response)]; mount &quot;/&quot; => builder { enable 'SimpleContentFilter', filter => sub { s{</head>}{$pod_highlight</head>}i; }; Plack::App::Proxy->new( remote => 'http://search.cpan.org/' )->to_app; }; }; $app; # Find full code sample at # http://github.com/oalders/cpan-mangler/blob/master/examples/pod-mangler.psgi
  • Known Issues
    • Doesn't perform perfectly
    • Can slow down page rendering on large pages (e.g. CGI.pm)
    • Some mangling may happen several times on a big page (chunking)
  • The Good Parts
    • Makes proxying dead easy
    • Improve your CPAN experience (be creative)
  • Beyond CPAN
    • can be used for Google ad tracking
    • proxy an entire site
    • set up a custom domain name for the proxy
    • direct all Google ads to this new domain
    • mangle the pages to add your own analytics code
    • site's existing functionality should remain the same
    • you can now replicate a site for tracking without making a copy of it or knowing/caring how it works under the hood