Want make a perl-module what basically:
My problem is: here is many different methods handling web request (decoding the query string), like (two notable ones are:)
$query->{‘somearg’}
or likeHow I should write the module, to be usable with different frontends?
Thinking about something like:
pakage MyJSONProducer::Plack; # for Plack based apps
use MyJSONProducer; # My module
my $prod = MyJSONProducer->new();
my $args = decode_plack_request_args($env); #make a hashref from args...
my $json = $prod->run($args); # call with args…
package MyJSONProducer::CGI; # for CGI based ones
use MyJSONProducer;
my $prod = MyJSONProducer->new();
my $args = decode_cgi_args($query); #make a hashref from args...
my $json = $prod->run($args); # call with args...
and so on…
But somewhat i feeling that this is not a very nice solution...
Is here some recommented way how to deal with this situation? Any CPAN module what i should study?
Just write MyJSONProducer::Plack. Then, if you want to deploy your app in a CGI environment, you can use something like Plack::Handler::CGI.
This is the point of Plack and PSGI. If you write your code to the PSGI specification then you can deploy it anywhere.