diff --git a/.circleci/config.yml b/.circleci/config.yml index e84dfa7..916fcd7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,29 +1,94 @@ -version: 2 +alias: + - &install_dzil + run: + command: | + cpm install -g --no-test Dist::Zilla Dist::Zilla::App::Command::cover ExtUtils::MakeMaker + name: Install Dzil + - &install_author_deps + run: + name: Install dzil author dependencies + command: | + cpm install --no-test -g \ + -w 2 \ + --mirror=http://cpan.cpantesters.org/ $(dzil authordeps --missing) + - &install_deps + run: + name: Install dist deps + command: | + # see https://github.com/team-at-cpan/Dist-Zilla-Plugin-PodInherit/issues/1 to check why we not use + # dzil listdeps --missing directly here + cpanm -n --installdeps . + dzil listdeps --author --missing --cpanm-versions | xargs cpanm -n + jobs: - build: + test: + parameters: + perl-version: + description: The Perl version we want to test with + type: string + default: "5.34" docker: - - image: debian:bullseye + - image: perldocker/perl-tester:<< parameters.perl-version >> steps: - checkout + - *install_dzil + - *install_author_deps + - *install_deps - run: - name: Install Perl packages - command: apt-get update && apt-get install -y cpanminus make gcc openssl libssl-dev zlib1g-dev git - - run: - name: Install dzil - command: cpanm --notest Dist::Zilla Dist::Zilla::App::Command::cover App::cpm Devel::Cover::Report::Codecov https://cpan.metacpan.org/authors/id/S/SR/SRI/Mojolicious-7.29.tar.gz https://cpan.metacpan.org/authors/id/B/BI/BINGOS/ExtUtils-MakeMaker-7.30.tar.gz - - run: - name: Install dzil author deps - command: cpm install --show-build-log-on-failure -w 2 --mirror=http://cpan.cpantesters.org/ -g $(dzil authordeps --missing) - - run: - name: Install distribution deps - command: cpm install --show-build-log-on-failure -w 2 --mirror=http://cpan.cpantesters.org/ -g $(dzil listdeps --author --missing) + name: Run Tests + command: | + dzil smoke --release --author && dzil cover -test -report codecov && dzil xtest + release: + docker: + - image: perldocker/perl-tester:5.34 + steps: + - checkout + - *install_dzil + - *install_author_deps + - *install_deps - run: - name: Run smoke test - command: dzil smoke --release --author + name: setup PAUSE account + command: | + echo -e "user $PAUSE_USER\npassword $PAUSE_PASSWORD\n" >> ~/.pause - run: - name: Run coverage test - command: dzil cover -test -report codecov + name: setup git + command: | + git config --global user.email "circleci@binary.com" + git config --global user.name "circleci" + # set remote github because dzil will push to github + # https://metacpan.org/release/DERIV/Dist-Zilla-PluginBundle-Author-DERIV-0.003/source/lib/Dist/Zilla/PluginBundle/Author/DERIV.pm#L122 + git remote add github $(git remote get-url origin) - run: - name: Run extended author test - command: dzil xtest + name: Release to PAUSE + command: | + if grep -Pzq '\{\{\$NEXT\}\}\n\s*\n' Changes + then + echo "No changes, no need release" + exit 0 + fi + # use git push to test permission + git push github master + echo "y\n" | DZIL_CONFIRMRELEASE_DEFAULT=y dzil release +workflows: + build-workflow: + jobs: &1 + - test: + matrix: + parameters: + perl-version: + - "5.24" + - "5.26" + - "5.28" + - "5.30" + - "5.32" + - "5.34" + - release: + context: release-binary + requires: + - test + filters: + branches: + only: + - master +version: 2.1 diff --git a/Changes b/Changes index aa39452..58bba61 100644 --- a/Changes +++ b/Changes @@ -1,8 +1,8 @@ Revision history for Perl module Mojo::WebSocketProxy {{$NEXT}} - - Move Mojo::WebSocketProxy::Backend::JobAsync and Mojo::WebSocketProxy::Backend::ConsumerGroups out -{{$NEXT}} +0.14 2022-11-09 07:45:53+00:00 UTC + - Move Mojo::WebSocketProxy::Backend::JobAsync and Mojo::WebSocketProxy::Backend::ConsumerGroups out - Add support for separating messages to different channels with different timeout values for each channel. - Increase minimum Perl version from 5.014 to 5.024 for the module. @@ -52,11 +52,11 @@ Revision history for Perl module Mojo::WebSocketProxy 0.04 2017-02-21 02:16:06+00:00 UTC - Switch to dzil -0.03 Thu Jun 9 15:50:00 2016 +0.03 2016-06-09 15:50:00 - Use before send hook to check response size -0.02 Thu Jun 9 09:28:00 2016 +0.02 2016-06-09 09:28:00 - Minor fixes -0.01 Thu Jun 2 06:02:18 2016 +0.01 2016-0602 06:02:18 - First version, released on an unsuspecting world. diff --git a/Makefile.PL b/Makefile.PL index e8d0e68..21f2b4e 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,43 +1,61 @@ -# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.012. +# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.024. use strict; use warnings; -use 5.014000; +use 5.024000; -use ExtUtils::MakeMaker 7.1101; +use ExtUtils::MakeMaker 7.64; my %WriteMakefileArgs = ( "ABSTRACT" => "WebSocket proxy for JSON-RPC 2.0 server", "AUTHOR" => "binary.com ", "CONFIGURE_REQUIRES" => { - "ExtUtils::MakeMaker" => "7.1101" + "ExtUtils::MakeMaker" => "7.64" }, "DISTNAME" => "Mojo-WebSocketProxy", "LICENSE" => "perl", - "MIN_PERL_VERSION" => "5.014000", + "MIN_PERL_VERSION" => "5.024000", "NAME" => "Mojo::WebSocketProxy", "PREREQ_PM" => { "Class::Method::Modifiers" => 0, + "Data::UUID" => 0, "DataDog::DogStatsd::Helper" => "0.05", + "Encode" => 0, "Future" => "0.36", "Future::Mojo" => "0.004", + "Future::Utils" => 0, "IO::Async::Loop::Mojo" => 0, "JSON::MaybeUTF8" => 0, - "Job::Async" => 0, + "Log::Any" => 0, + "Mojo::Base" => 0, + "Mojo::Redis2" => 0, + "Mojo::Util" => 0, "MojoX::JSON::RPC" => 0, + "MojoX::JSON::RPC::Client" => 0, "Mojolicious" => "7.29", "Scalar::Util" => 0, + "Syntax::Keyword::Try" => "0.04", "Unicode::Normalize" => "1.25", + "constant" => 0, "curry" => "1.001", + "feature" => 0, "indirect" => 0, - "Mojo::Redis2" => 0, - "Data::UUID" => 0 + "parent" => 0, + "strict" => 0, + "warnings" => 0 }, "TEST_REQUIRES" => { + "Exporter" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, + "Future" => "0.36", "IO::Handle" => 0, "IPC::Open3" => 0, + "JSON::MaybeXS" => 0, + "Mojo::IOLoop" => 0, + "MojoX::JSON::RPC::Service" => 0, + "Mojolicious" => "7.29", + "Net::EmptyPort" => 0, "Path::Tiny" => 0, "Test::CheckDeps" => "0.010", "Test::Fatal" => 0, @@ -46,9 +64,11 @@ my %WriteMakefileArgs = ( "Test::Mojo" => 0, "Test::More" => "0.98", "Test::Simple" => "0.44", - "Test::TCP" => 0 + "Test::TCP" => 0, + "Test::Warnings" => 0, + "base" => 0 }, - "VERSION" => "0.13", + "VERSION" => "0.15", "test" => { "TESTS" => "t/*.t" } @@ -57,20 +77,33 @@ my %WriteMakefileArgs = ( my %FallbackPrereqs = ( "Class::Method::Modifiers" => 0, + "Data::UUID" => 0, "DataDog::DogStatsd::Helper" => "0.05", + "Encode" => 0, + "Exporter" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "Future" => "0.36", "Future::Mojo" => "0.004", + "Future::Utils" => 0, "IO::Async::Loop::Mojo" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "JSON::MaybeUTF8" => 0, - "Job::Async" => 0, + "JSON::MaybeXS" => 0, + "Log::Any" => 0, + "Mojo::Base" => 0, + "Mojo::IOLoop" => 0, + "Mojo::Redis2" => 0, + "Mojo::Util" => 0, "MojoX::JSON::RPC" => 0, + "MojoX::JSON::RPC::Client" => 0, + "MojoX::JSON::RPC::Service" => 0, "Mojolicious" => "7.29", + "Net::EmptyPort" => 0, "Path::Tiny" => 0, "Scalar::Util" => 0, + "Syntax::Keyword::Try" => "0.04", "Test::CheckDeps" => "0.010", "Test::Fatal" => 0, "Test::MockModule" => 0, @@ -79,9 +112,16 @@ my %FallbackPrereqs = ( "Test::More" => "0.98", "Test::Simple" => "0.44", "Test::TCP" => 0, + "Test::Warnings" => 0, "Unicode::Normalize" => "1.25", + "base" => 0, + "constant" => 0, "curry" => "1.001", - "indirect" => 0 + "feature" => 0, + "indirect" => 0, + "parent" => 0, + "strict" => 0, + "warnings" => 0 ); diff --git a/README.md b/README.md index bb2bb53..d46027d 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,12 @@ -# perl-Mojo-WebSocketProxy - -[![Build Status](https://travis-ci.org/binary-com/perl-Mojo-WebSocketProxy.svg?branch=master)](https://travis-ci.org/binary-com/perl-Mojo-WebSocketProxy) -[![codecov](https://codecov.io/gh/binary-com/perl-Mojo-WebSocketProxy/branch/master/graph/badge.svg)](https://codecov.io/gh/binary-com/perl-Mojo-WebSocketProxy) - -#### INSTALLATION - -To install this module, run the following commands: - - perl Makefile.PL - make - make test - make install - -#### NAME +# NAME Mojo::WebSocketProxy - WebSocket proxy for JSON-RPC 2.0 server -#### SYNOPSYS +# SYNOPSIS # lib/your-application.pm - use base 'Mojolicious'; + use parent 'Mojolicious'; sub startup { my $self = shift; @@ -39,7 +25,7 @@ Or to manually call RPC server: # lib/your-application.pm - use base 'Mojolicious'; + use parent 'Mojolicious'; sub startup { my $self = shift; @@ -51,8 +37,8 @@ Or to manually call RPC server: { instead_of_forward => sub { shift->call_rpc({ - args => $args, - method => $rpc_method, # it'll call 'http://rpc-host.com:8080/rpc_method' + args => [ qw(args here) ], + method => 'json_key', # it'll call 'http://rpc-host.com:8080/json_key' rpc_response_cb => sub {...} }); } @@ -65,7 +51,7 @@ Or to manually call RPC server: ); } -#### DESCRIPTION +# DESCRIPTION Using this module you can forward WebSocket-JSON requests to RPC server. @@ -74,7 +60,7 @@ Request storage have RPC call parameters in $req\_storage->{call\_params}. It copies message args to $req\_storage->{call\_params}->{args}. You can use Mojolicious stash to store data between messages in one connection. -#### Proxy responses +# Proxy responses The plugin sends websocket messages to client with RPC response data. If RPC reponse looks like this: @@ -99,64 +85,15 @@ Plugin returns common response like this: msg_type => $msg_type, } -You can customize ws porxy response using 'response' hook. - -#### Sequence Diagram - -![Alt text](https://g.gravizo.com/source/ws_proxy?https%3A%2F%2Fraw.githubusercontent.com%2Fbinary-com%2Fperl-Mojo-WebSocketProxy%2Fmaster%2FREADME.md) -
- -ws_proxy -@startuml; -title Websocket Proxy - -participant Client - -Client->Websocket:Initiate connection -Client->Websocket:Send Message - -note over Websocket: before_forward -note over Websocket: instead_of_forward - -Websocket->Websocket: instead_of_forward does not forward to rpc and returns response back from ws if its valid one - -Websocket->Client: send response (only if instead_of_forward) - -note over Websocket: before_call +You can customize ws proxy response using 'response' hook. -Websocket->RPC: RPC request - -note over Websocket: after_forward -note over Websocket: after_dispatch - -note over RPC: processing - -note over Websocket: before_got_rpc_response - -RPC->Websocket: RPC response - -note over Websocket: after_got_rpc_response -note over Websocket: success/error -note over Websocket: response -note over Websocket: before_send_api_response -note over Websocket: send - -Websocket->Client:send response back - -note over Websocket: after_send_api_response - -Client->Websocket:Close Websocket connection -@enduml -ws_proxy -
- -#### Plugin parameters +# Plugin parameters The plugin understands the following parameters. -##### actions +## actions -A pointer to array of action details, which contain stash\_params, +A reference to array of action details, which contain stash\_params, request-response callbacks, other call parameters. $self->plugin( @@ -167,125 +104,162 @@ request-response callbacks, other call parameters. ] }); -##### before\_forward +## backends - before_forward => [sub { my ($c, $req_storage) = @_; ... }, sub {...}] +An optional reference to a hash of alternate backends to pick for certain RPC +calls. Hash keys are names of backends, and values are themselves hash +references containing backend parameters. Currently only the `url` key is +supported. -Global hook which will run after request is dispatched and before to start preparing RPC call. -It'll run every hook or until any hook returns some non-empty result. -If returns any hash ref then that value will be JSON encoded and send to client, -without forward action to RPC. To call RPC every hook should return empty or undefined value. -It's good place to some validation or subscribe actions. + backends => { + server2 => {url => "http://server2.rpc-host:8080/"}, + } + +Alternate backends are selected by using the `backend` action option. + +## rpc\_failure\_cb -#### instead\_of\_forward (global) +A subroutine reference to call when the RPC call fails at the HTTP level. +Called with `Mojolicious::Controller` the rpc\_response +and `$req_storage` + +A default rpc\_failure\_cb could be provided in the startup sub routine + + sub startup { + my $self = shift; + $self->plugin( + 'web_socket_proxy' => { + actions => [ + ['json_key', {some_param => 'some_value'}] + ], + base_path => '/api', + url => 'http://rpc-host.com:8080/', + rpc_failure_cb => sub { + my ($c, $res, $req_storage, $error) = @_; + warn "RPC call failed"; + return undef; + } - instead_of_forward => [sub { my ($c, $req_storage) = @_; ... }, sub {...}] + } + ); + } -Use this hook if you don't want dispatcher to call RPC and want to handle request -in websocket itself. It's not good practice to use it as global hook because if -if you return response from sub passed then it will return same response for each -call. [Read more](#instead-of-forward) +Call specific sub routine could be specified in call\_rpc arguments + + $c->call_rpc({ + args => $args, + origin_args => $req_storage->{origin_args}, + method => 'ticks_history', + rpc_failure_cb => sub { + if ($worker) { + warn "Something went wrong with this rpc call : " . $method; + $worker->unregister; + } + }, + } -#### before\_call (global) +## before\_forward - before_call => [sub { my ($c, $req_storage) = @_; ... }, sub {...}] + before_forward => [sub { my ($c, $req_storage) = @_; ... }, sub {...}] -Global hook which will run just before making rpc call. +Global hooks which will run after request is dispatched and before to start preparing RPC call. +It'll run every hook or until any hook returns some non-empty result. +If returns any hash ref then that value will be JSON encoded and send to client, +without forward action to RPC. To call RPC every hook should return empty or undefined value. +It's good place to some validation or subscribe actions. -##### after\_forward (global) +## after\_forward after_forward => [sub { my ($c, $result, $req_storage) = @_; ... }, sub {...}] -Global hook which will run after every forwarded RPC call done. +Global hooks which will run after every forwarded RPC call done. Or even forward action isn't running. It can view or modify result value from 'before\_forward' hook. It'll run every hook or until any hook returns some non-empty result. If returns any hash ref then that value will be JSON encoded and send to client. -##### after\_dispatch (global) +## after\_dispatch after_dispatch => [sub { my $c = shift; ... }, sub {...}] -Global hook which will run at the end of request handling. +Global hooks which will run at the end of request handling. -##### before\_get\_rpc\_response (global) +## before\_get\_rpc\_response (global) before_get_rpc_response => [sub { my ($c, $req_storage) = @_; ... }, sub {...}] -Global hook which will run when asynchronous RPC call is answered. +Global hooks which will run when asynchronous RPC call is answered. -##### after\_got\_rpc\_response (global) +## after\_got\_rpc\_response (global) after_got_rpc_response => [sub { my ($c, $req_storage) = @_; ... }, sub {...}] -Global hook which will run after checked that response exists. +Global hooks which will run after checked that response exists. -##### before\_send\_api\_response (global) +## before\_send\_api\_response (global) before_send_api_response => [sub { my ($c, $req_storage, $api_response) = @_; ... }, sub {...}] -Global hook which will run immediately before send API response. +Global hooks which will run immediately before send API response. -##### after\_sent\_api\_response (global) +## after\_sent\_api\_response (global) before_send_api_response => [sub { my ($c, $req_storage) = @_; ... }, sub {...}] -Global hook which will run immediately after sent API response back to client. +Global hooks which will run immediately after sent API response. -##### base\_path +## base\_path API url for make route. -##### stream\_timeout +## stream\_timeout -See ["timeout" in Mojo::IOLoop::Stream](https://metacpan.org/pod/Mojo::IOLoop::Stream#timeout) +See ["timeout" in Mojo::IOLoop::Stream](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AStream#timeout) -##### max\_connections +## max\_connections -See ["max\_connections" in Mojo::IOLoop](https://metacpan.org/pod/Mojo::IOLoop#max_connections) +See ["max\_connections" in Mojo::IOLoop](https://metacpan.org/pod/Mojo%3A%3AIOLoop#max_connections) -##### max\_response\_size +## max\_response\_size Returns error if RPC response size is over value. -##### opened\_connection +## opened\_connection Callback for doing something once after connection is opened -##### finish\_connection +## finish\_connection Callback for doing something every time when connection is closed. -##### url +## url RPC host url - store url string or function to set url dynamically for manually RPC calls. When using forwarded call then url storing in request storage. You can store url in every action options, or make it at before\_forward hook. -#### Actions options +# Actions options -##### stash\_params +## stash\_params stash_params => [qw/ stash_key1 stash_key2 /] -Use this if you want to send specified parameters from Mojolicious $c->stash to RPC. -RPC will receive this as part of call params. - +Will send specified parameters from Mojolicious $c->stash. You can store RPC response data to Mojolicious stash returning data like this: rpc_response => { - stash => {..} # data to store in Mojolicious stash + stast => {..} # data to store in Mojolicious stash response_key1 => response_value1, # response to API client response_key2 => response_value2 } -##### success +## success success => sub { my ($c, $rpc_response) = @_; ... } Hook which will run if RPC returns success value. -##### error +## error error => sub { my ($c, $rpc_response) = @_; ... } @@ -293,41 +267,29 @@ Hook which will run if RPC returns value with error key, e.g. { result => { error => { code => 'some_error' } } } -##### response +## response response => sub { my ($c, $rpc_response) = @_; ... } Hook which will run every time when success or error callbacks is running. It good place to modify API response format. -#### Instead of forward - -This hook is generally used if you don't want to forward request to RPC and want -to handle it within websocket itself, for example like send back server time. +## backend -Another case where its useful is if you don't want to send response to rpc url -provided in global scope and want to forward to separate RPC service (useful if -you have multiple RPC service to handle different type of request) +Selects an alternative backend to forward requests onto, rather than the +default. -``` - instead_of_forward => sub { - shift->call_rpc({ - url => 'some other rpc url', - args => $args, - method => $rpc_method, # it'll call 'http://rpc-host.com:8080/rpc_method' - rpc_response_cb => sub {...} - }); -``` + backend => "server2" -#### SEE ALSO +# SEE ALSO -[Mojolicious::Plugin::WebSocketProxy](https://metacpan.org/pod/Mojolicious::Plugin::WebSocketProxy), -[Mojo::WebSocketProxy](https://metacpan.org/pod/Mojo::WebSocketProxy) -[Mojo::WebSocketProxy::CallingEngine](https://metacpan.org/pod/Mojo::WebSocketProxy::CallingEngine), -[Mojo::WebSocketProxy::Dispatcher](https://metacpan.org/pod/Mojo::WebSocketProxy::Dispatcher), -[Mojo::WebSocketProxy::Config](https://metacpan.org/pod/Mojo::WebSocketProxy::Config) -[Mojo::WebSocketProxy::Parser](https://metacpan.org/pod/Mojo::WebSocketProxy::Parser) +[Mojolicious::Plugin::WebSocketProxy](https://metacpan.org/pod/Mojolicious%3A%3APlugin%3A%3AWebSocketProxy), +[Mojo::WebSocketProxy](https://metacpan.org/pod/Mojo%3A%3AWebSocketProxy) +[Mojo::WebSocketProxy::Backend](https://metacpan.org/pod/Mojo%3A%3AWebSocketProxy%3A%3ABackend), +[Mojo::WebSocketProxy::Dispatcher](https://metacpan.org/pod/Mojo%3A%3AWebSocketProxy%3A%3ADispatcher), +[Mojo::WebSocketProxy::Config](https://metacpan.org/pod/Mojo%3A%3AWebSocketProxy%3A%3AConfig) +[Mojo::WebSocketProxy::Parser](https://metacpan.org/pod/Mojo%3A%3AWebSocketProxy%3A%3AParser) -#### COPYRIGHT AND LICENSE +# COPYRIGHT AND LICENSE Copyright (C) 2016 binary.com diff --git a/cpanfile b/cpanfile index a589906..7a903ae 100644 --- a/cpanfile +++ b/cpanfile @@ -11,7 +11,7 @@ requires 'Scalar::Util'; requires 'Unicode::Normalize', '>= 1.25'; requires 'DataDog::DogStatsd::Helper', '>= 0.05'; requires 'Syntax::Keyword::Try', '>= 0.04'; -requires 'perl', '5.024'; +requires 'perl', '>= 5.024000'; requires 'Mojo::Redis2'; requires 'Data::UUID'; requires 'Log::Any'; diff --git a/dist.ini b/dist.ini index cbb30c5..5c22f30 100644 --- a/dist.ini +++ b/dist.ini @@ -1,69 +1,16 @@ name = Mojo-WebSocketProxy author = binary.com license = Perl_5 -copyright_holder = binary.com -copyright_year = 2017 +copyright_holder = Binary Services Ltd +copyright_year = 2022 -[Git::GatherDir] -exclude_filename = Makefile.PL -include_dotfiles = 1 -[PruneCruft] -except = t/rc/\.perl.*rc$ -[ManifestSkip] -[MetaYAML] -[License] -[Readme] -[MakeMaker] -eumm_version = 7.1101 -prereq_fatal = 1 -[ExecDir] -[ShareDir] -dir = share -[Manifest] -[TestRelease] -[ConfirmRelease] -[Prereqs::FromCPANfile] -[Prereqs / BuildRequires] -perl = 5.014000 -[CheckPrereqsIndexed] -[CheckExtraTests] -[VersionFromModule] -[ReversionOnRelease] -[NextRelease] -[OurPkgVersion] -[GitHub::Meta] -repo = binary-com/perl-Mojo-WebSocketProxy -[InstallGuide] -[MetaJSON] -[InsertExample] +[@Author::DERIV] +allow_dirty = lib/Mojo/WebSocketProxy.pm +max_target_perl = 5.24.0 +[Encoding] +encoding = bytes +match = ^t/data/.*\.png$ [PerlTidy] -perltidyrc = t/rc/.perltidyrc -[PodSyntaxTests] -[MojibakeTests] -[Test::CheckDeps] -[Test::Compile] -[Test::Synopsis] -;[Test::EOL] -[Test::Version] -[Test::Pod::LinkCheck] -[PodCoverageTests] -;[Test::UnusedVars] -[Test::ReportPrereqs] +perltidyrc = t/rc/perltidyrc [Test::Perl::Critic] -critic_config = t/rc/.perlcriticrc -[SpellingCommonMistakesTests] -[CopyFilesFromRelease] -filename = lib/Mojo/WebSocketProxy.pm -filename = Makefile.PL -[Git::Commit] -allow_dirty = dist.ini -allow_dirty = cpanfile -allow_dirty = Changes -allow_dirty = Makefile.PL -allow_dirty = lib/Mojo/WebSocketProxy.pm -[Git::Tag] -tag_format = v%v -tag_message = Tag v%v for CPAN release -[InstallRelease] -install_command = carton install -[UploadToCPAN] +critic_config = t/rc/perlcriticrc diff --git a/lib/Mojo/WebSocketProxy.pm b/lib/Mojo/WebSocketProxy.pm index 2e2f27a..cc2abc0 100644 --- a/lib/Mojo/WebSocketProxy.pm +++ b/lib/Mojo/WebSocketProxy.pm @@ -3,7 +3,7 @@ package Mojo::WebSocketProxy; use strict; use warnings; -our $VERSION = '0.13'; +our $VERSION = '0.15'; 1; @@ -130,8 +130,8 @@ Alternate backends are selected by using the C action option. =head2 rpc_failure_cb -A subroutine reference to call when the RPC call fails at the HTTP level. -Called with C<< Mojolicious::Controller >> the rpc_response +A subroutine reference to call when the RPC call fails at the HTTP level. +Called with C<< Mojolicious::Controller >> the rpc_response and C<< $req_storage >> A default rpc_failure_cb could be provided in the startup sub routine diff --git a/lib/Mojo/WebSocketProxy/Backend/JSONRPC.pm b/lib/Mojo/WebSocketProxy/Backend/JSONRPC.pm index c10747e..f9f18bd 100644 --- a/lib/Mojo/WebSocketProxy/Backend/JSONRPC.pm +++ b/lib/Mojo/WebSocketProxy/Backend/JSONRPC.pm @@ -23,52 +23,52 @@ my $request_number = 0; =head2 call_rpc -Description: Makes a remote call to a process returning the result to the client in JSON format. +Description: Makes a remote call to a process returning the result to the client in JSON format. Before, After and error actions can be specified using call backs. -It takes the following arguments +It takes the following arguments =over 4 =item - $c : L -=item - $req_storage A hashref of attributes stored with the request. This routine uses some of the, -following named arguments. +=item - $req_storage A hashref of attributes stored with the request. This routine uses some of the +following named arguments. -=over 4 +=over 4 -=item - url, if not specified url set on C<< $self >> object is used. Must be supplied by either method. +=item - url, if not specified url set on C<< $self >> object is used. Must be supplied by either method. =item - method, The name of the method at the remote end (this is appened to C<< $request_storage->{url} >> ) -=item - msg_type, a name for this method if not supplied C is used. +=item - msg_type, a name for this method if not supplied C is used. =item - call_params, a hashref of arguments on top of C to send to remote method. This will be suplemented with C<< $req_storage->{args} >> -added as an C key and be merged with C<< $req_storage->{stash_params} >> with stash_params overwriting any matching -keys in C. +added as an C key and be merged with C<< $req_storage->{stash_params} >> with stash_params overwriting any matching +keys in C. -=item - rpc_response_callback, If supplied this will be run with C<< Mojolicious::Controller >> instance the rpc_response and C<< $req_storage >>. -B if C<< rpc_response_callback >> is supplied the success and error callbacks are not used. +=item - rpc_response_callback, If supplied this will be run with C<< Mojolicious::Controller >> instance the rpc_response and C<< $req_storage >>. +B if C<< rpc_response_callback >> is supplied the success and error callbacks are not used. -=item - before_get_rpc_response, array ref of subroutines to run before the remote response, is passed C<< $c >> and C<< req_storage >> +=item - before_get_rpc_response, array ref of subroutines to run before the remote response, is passed C<< $c >> and C<< req_storage >> -=item - after_get_rpc_response, arrayref of subroutines to run after the remote response, is passed C<< $c >> and C<< req_storage >> -called only when there is an actual response from the remote call . IE if there is communication error with the call it will -not be called versus an error message being returned from the call when it will. +=item - after_get_rpc_response, arrayref of subroutines to run after the remote response, is passed C<< $c >> and C<< req_storage >> +called only when there is an actual response from the remote call . IE if there is communication error with the call it will +not be called versus an error message being returned from the call when it will. -=item - before_call, arrayref of subroutines called before the request to the remote service is made. +=item - before_call, arrayref of subroutines called before the request to the remote service is made. -=item - error, a subroutine reference that will be called with C<< Mojolicious::Controller >> the rpc_response and C<< $req_storage >> -if a C<< $response->{error} >> error was returned from the remote call, and C<< $req_storage->{rpc_response_cb} >> was not passed. +=item - error, a subroutine reference that will be called with C<< Mojolicious::Controller >> the rpc_response and C<< $req_storage >> +if a C<< $response->{error} >> error was returned from the remote call, and C<< $req_storage->{rpc_response_cb} >> was not passed. -=item - success, a subroutines reference that will be called if there was no error returned from the remote call and C<< $req_storage->{rpc_response_cb} >> was not passed. +=item - success, a subroutines reference that will be called if there was no error returned from the remote call and C<< $req_storage->{rpc_response_cb} >> was not passed. -=item - rpc_failure_cb, a sub routine reference to call if the remote call fails at a http level. Called with C<< Mojolicious::Controller >> the rpc_response and C<< $req_storage >> +=item - rpc_failure_cb, a sub routine reference to call if the remote call fails at a http level. Called with C<< Mojolicious::Controller >> the rpc_response and C<< $req_storage >> =back -=back +=back -Returns undef. +Returns undef. =cut diff --git a/lib/Mojo/WebSocketProxy/Dispatcher.pm b/lib/Mojo/WebSocketProxy/Dispatcher.pm index 707f1ff..f0c2a74 100644 --- a/lib/Mojo/WebSocketProxy/Dispatcher.pm +++ b/lib/Mojo/WebSocketProxy/Dispatcher.pm @@ -293,8 +293,6 @@ Handle message - parse and dispatch request messages. Dispatching action and forward to RPC server. Note that all incoming JSON messages are first normalised using L. - - =head2 before_forward diff --git a/t/rc/.perlcriticrc b/t/rc/perlcriticrc similarity index 100% rename from t/rc/.perlcriticrc rename to t/rc/perlcriticrc diff --git a/t/rc/.perltidyrc b/t/rc/perltidyrc similarity index 100% rename from t/rc/.perltidyrc rename to t/rc/perltidyrc