{"id":18284503,"url":"https://github.com/pplu/pawsx-fakeimplementation-instance","last_synced_at":"2025-08-13T02:46:14.688Z","repository":{"id":56832600,"uuid":"98204633","full_name":"pplu/pawsx-fakeimplementation-instance","owner":"pplu","description":"PawsX::FakeImplementation::Instance - A Paws extension to help you write fake AWS services","archived":false,"fork":false,"pushed_at":"2017-07-25T10:36:42.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-15T00:25:51.039Z","etag":null,"topics":["fake-implementations","paws","paws-callers","pluggable-callers"],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pplu.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-24T15:15:23.000Z","updated_at":"2018-05-17T09:13:23.000Z","dependencies_parsed_at":"2022-09-08T05:11:11.852Z","dependency_job_id":null,"html_url":"https://github.com/pplu/pawsx-fakeimplementation-instance","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pplu%2Fpawsx-fakeimplementation-instance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pplu%2Fpawsx-fakeimplementation-instance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pplu%2Fpawsx-fakeimplementation-instance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pplu%2Fpawsx-fakeimplementation-instance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pplu","download_url":"https://codeload.github.com/pplu/pawsx-fakeimplementation-instance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247987107,"owners_count":21028891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fake-implementations","paws","paws-callers","pluggable-callers"],"created_at":"2024-11-05T13:13:45.666Z","updated_at":"2025-04-09T05:46:48.555Z","avatar_url":"https://github.com/pplu.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nPawsX::FakeImplementation::Instance - A Paws extension to help you write fake AWS services\n\n# SYNOPSIS\n\n    use Paws;\n    use Paws::Net::MultiplexCaller;\n    use PawsX::FakeImplementation::Instance;\n\n    my $paws = Paws-\u003enew(\n      config =\u003e {\n        caller =\u003e Paws::Net::MultiplexCaller-\u003enew(\n          caller_for =\u003e {\n            SQS =\u003e PawsX::FakeImplementation::Instance-\u003enew(\n              api_class =\u003e 'FakeSQS',\n            ),\n          }\n        ),\n      }\n    );\n\n    my $sqs = $paws-\u003eservice('SQS', region =\u003e 'test');\n    my $new_queue = $sqs-\u003eCreateQueue(QueueName =\u003e 'MyQueue');\n    # the FakeSQS implementation has returned a $new_queue object just\n    # like SQS would:\n    # $new_queue-\u003eQueueUrl eq 'http://sqs.fake.amazonaws.com/123456789012/MyQueue'\n\n    my $qurl = $result-\u003eQueueUrl;\n    \n    my $sent_mess = $sqs-\u003eSendMessage(MessageBody =\u003e 'Message 1', QueueUrl =\u003e $new_queue-\u003eQueueUrl);\n    # $sent_mess-\u003eMessageId has a unique id\n\n    my $rec_mess = $sqs-\u003eReceiveMessage(QueueUrl =\u003e $qurl);\n    # $rec_mess-\u003eMessages-\u003e[0]-\u003eBody eq 'Message 1'\n\n# DESCRIPTION\n\nWhen working heavily with AWS services you will sometimes have special needs:\n\n- Working on a plane (or in situations with limited connectivity)\n- Testing your application\n- Generating faults\n\nPawsX::FakeImplementation::Instance will help you create fake implementations for any service you\nwant. You will be able to emulate any service of your choice, and implement the behaviour you need to\nbe tested.\n\nPawsX::FakeImplementation::Instance teams up with Paws::Net::MultiplexCaller to route the appropiate\nservice calls to the appropiate fake implementation. See [Paws::Net::MultiplexCaller](https://metacpan.org/pod/Paws::Net::MultiplexCaller) for more info\n\n# Creating a fake implementation\n\nPawsX::FakeImplementation::Instance defines an interface between the fake implementations and Paws so\nthat it's easy to write these fake implementations. Here's a guide by example to do it:\n\n## Create your fake implementation class\n\nWe start out creating a new class for our fake service:\n\n    package My::Fake::SQS;\n      use Moose;\n\n    1;\n\nBe careful with namespacing: take into account that your fake implementation could be partial \n(not a full emulation of the service), or your fake could have specialized behaviour like:\n\n- Only implementing a subset of calls\n- Only implementing partial behaviour for some calls (feature incomplete)\n- Implements some type of failure mode (fails one of every 10 calls to the service)\n\nSo please try to name your fakes accordingly: `My::Fake::BasicSQS`, `My::Fake::SQS::OutOfOrder`, \n`My::FakeSQS::OnlyAdministrativeCalls`, `My::FakeSQS::FailSomeCalls`\n\nIf you are going to write a generic fake, trying to closely emulate the AWS service, you can use \nthe `PawsX::FakeService::SERVICE_NAME` namespace.\n\nPlease have the behaviour of these generic fakes well tested and be willing to accept contributions \nfrom third parties to these fakes, as people will probably turn to those implementations by default\nto test services. Please document any already known differences between the real service and the \nfake service.\n\n## Write a fake method\n\nJust create a sub named like the method you want to fake in your fake service class. It will receive\nan object with the parameters that were passed to the service:\n\n    sub CreateQueue {\n      my ($self, $params) = @_;\n      # $params-\u003eQueueName holds what the user passed to \n      #   $sqs-\u003eCreateQueue(QueueName =\u003e '...');\n      return { QueueUrl =\u003e 'http://myqueue' };\n    }\n\nThe $params object in this case is a `Paws::SQS::CreateQueue` object (that represents the parameters\nto the CreateQueue call.\n\n## Return values\n\nThe return of CreateQueue is a hashref that contains the attributes for inflating a `Paws::SQS::CreateQueueResult`. \nPawsX::FakeImplementation::Instance will convert the hashref to the appropiate return object that the calling \ncode is expecting.\n\n    sub CreateQueue {\n      return { QueueUrl =\u003e 'http://myqueue' };\n    }\n\nfrom the fake implementation will be received in the calling side as always:\n\n    my $return = $sqs-\u003eCreateQueue(QueueName =\u003e 'x');\n    print $return-\u003eQueueUrl; # http://myqueue\n\n## Controlled exceptions\n\nIf the code inside a fake implementation throws or returns a Paws::Exception, the \"user code\" will recieve the \nPaws::Exception just like if Paws had generated it.\n\n    sub CreateQueue {\n      Paws::Exception-\u003ethrow(message =\u003e 'The name is duplicate', code =\u003e 'DuplicateName');\n    }\n\nThis helps emulate error conditions just like Paws/AWS returns them\n\n## Uncontrolled exceptions\n\nIf the code inside a fake implementation dies, PawsX::FakeImplementation::Instance will wrap it inside a generic\nPaws::Exception object with code 'InternalError' and the exception as the message. Paws' contract with the \noutside world is to throw Paws::Exception objects in case of problems, so PawsX::FakeImplementation::Instance\ntries to not bubble non-Paws-compliant exceptions.\n\n## Instance Storage\n\nPawsX::FakeImplementation::Instance instances your object one time only, and after that routes method calls\nto your object. This lets you use an attribute to store data for the lifetime of your object, and use it\nas \"storage\". A queue service, for example could use\n\n    has _queue =\u003e (is =\u003e 'ro', isa =\u003e 'ArrayRef');\n\nas storage for the messages it enqueues. Every call to the fake services methods will see $self-\u003e\\_queue, and\nbe able to manipulate it:\n\n    sub ReceiveMessage {\n      my ($self, $params) = @_;\n\n      my $message = pop @{ $self-\u003e_queue };\n      return { Messages =\u003e $message };\n    } \n\n## Externally configurable attributes\n\nIf you want your fake service to be configurable in some way, you can specify an attribute in your\nfake service class.\n\n    package My::Fake::FailingSQS;\n      use Moose;\n\n      has failing_call_ratio =\u003e (is =\u003e 'ro', isa =\u003e 'Num', default =\u003e 0.5);\n\n      sub CreateQueue {\n        my ($self, $params) = @_;\n        die \"Strange error\" if (rand() \u003c $self-\u003efailing_call_ratio);\n      }\n\n    1;\n\nThe user of the fake service can then initialize it in the following way:\n\n     my $paws = Paws-\u003enew(\n      config =\u003e {\n        caller =\u003e Paws::Net::MultiplexCaller-\u003enew(\n          caller_for =\u003e {\n            SQS =\u003e PawsX::FakeImplementation::Instance-\u003enew(\n              api_class =\u003e 'My::Fake::FailingSQS',\n              params =\u003e {\n                failing_call_ratio =\u003e 1 # all calls fail\n              }\n            ),\n          }\n        ),\n      }\n    );\n\nIt's recommended that your attribute either has a default (for easy usage), or declares itself as required\nas to guide the consumer of the fake service what parameters need to be passed.\n\n# AUTHOR\n\n    Jose Luis Martinez\n    CPAN ID: JLMARTIN\n    CAPSiDE\n    jlmartinez@capside.com\n\n# SEE ALSO\n\n[Paws](https://metacpan.org/pod/Paws)\n\n[Paws::Net::MultiplexCaller](https://metacpan.org/pod/Paws::Net::MultiplexCaller)\n\n[https://github.com/pplu/aws-sdk-perl](https://github.com/pplu/aws-sdk-perl)\n\n# BUGS and SOURCE\n\nThe source code is located here: [https://github.com/pplu/pawsx-fakeimplementation-instance](https://github.com/pplu/pawsx-fakeimplementation-instance)\n\nPlease report bugs to: [https://github.com/pplu/pawsx-fakeimplementation-instance/issues](https://github.com/pplu/pawsx-fakeimplementation-instance/issues)\n\n# COPYRIGHT and LICENSE\n\nCopyright (c) 2017 by CAPSiDE\n\nThis code is distributed under the Apache 2 License. The full text of the license can be found in the LICENSE file included with this module.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpplu%2Fpawsx-fakeimplementation-instance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpplu%2Fpawsx-fakeimplementation-instance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpplu%2Fpawsx-fakeimplementation-instance/lists"}