The learning curve for POE isn't really that big if you start with a simple problem like this. Here is a simple little POE-based script that can give you an easily expandable REST-style http interface for doing the kinds of things you want to do...

#!/usr/bin/perl use warnings; use strict; use POE qw( Component::Server::HTTP ); use HTTP::Status; my $VERSION = '0.01'; POE::Component::Server::HTTP->new( Port => 42421, ContentHandler => { "/" => \&uri_handler, }, Headers => { Version => $VERSION }, ); POE::Kernel->run(); sub uri_handler { my ( $request, $response ) = @_; my $path = $request->uri->path; $path =~ s/\W+/_/g; $path = "remote_request".$path; # see update $response->content_type( 'text/plain' ); if ( ! defined &$path ) { $response->code( RC_NOT_FOUND ); return RC_OK; } my $content = eval { no strict 'refs'; &$path }; if ( $@ ) { $response->code( RC_INTERNAL_SERVER_ERROR ); warn $@; $response->content( "ERROR: $@" ); return RC_OK; } $response->code( RC_OK ); $response->content($content); return RC_OK; } sub remote_request_version { return "$VERSION\n" }

In this little server, the uri path that is requested just gets turned into a sub name (so a request for /version becomes _version), and if that sub exists, then it's output is returned as the HTTP response. This way you can add new features just by adding new subroutines.

Update: merlyn is right, I oversimplified a little while posting this, and a little more care should be taken with the functions you expose to this type of application. I added "remote_request" to the beginning of any functions that are accessible from the web interface to mitigate this.


We're not surrounded, we're in a target-rich environment!

In reply to Re: Simple TCP server recomendations by jasonk
in thread Simple TCP server recomendations by Random_Walk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.