curl2lwp - convert Curl command line arguments to LWP / Mechanize Perl code

After inspiration by a comment on Perlmonks.org and some slight hacking, I'm very proud to announce HTTP::Request::FromCurl, together with its companion online site at https://corion.net/curl2lwp.psgi. The module and included curl2lwp program allow you to easily convert curl command lines to Perl code that uses LWP::UserAgent resp. WWW::Mechanize.

Some code:

    curl2lwp.pl -X GET -A xpcurl/1.0 https://perlmonks.org/

outputs the following code:


    my $ua = WWW::Mechanize->new();
    my $r = HTTP::Request->new(
        'GET' => 'https://perlmonks.org/',
        [
            'Accept' => '*/*',
            'Host' => 'perlmonks.org:443',
            'User-Agent' => 'curl/1.0',
        ],
    );
    my $res = $ua->request( $r,  );

The online version creates a bit more code, as the output there is likely not consumed by advanced Perl programmers.

The module parses a subset of the valid curl command lines and generates equivalent code for LWP::UserAgent for it. Support for other HTTP user agents Mojo::UserAgent, AnyEvent::HTTP, Future::HTTP ) is not yet implemented but I welcome contributions there.

The app driving the online interface is not yet released onto CPAN, but as it is mostly HTML scaffolding and some Javascript, it should be released fairly soon.

Leave a comment

About Max Maischein

user-pic I'm the Treasurer for the Frankfurt Perlmongers e.V. . I have organized Perl events including 9 German Perl Workshops and one YAPC::Europe.