{"id":18538690,"url":"https://github.com/hatena/p5-test-www-stub","last_synced_at":"2025-10-24T22:37:36.169Z","repository":{"id":27707708,"uuid":"31194618","full_name":"hatena/p5-Test-WWW-Stub","owner":"hatena","description":null,"archived":false,"fork":false,"pushed_at":"2025-10-21T06:39:17.000Z","size":94,"stargazers_count":3,"open_issues_count":6,"forks_count":6,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-10-24T22:37:35.802Z","etag":null,"topics":["perl","testing"],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hatena.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-23T04:59:24.000Z","updated_at":"2023-01-11T13:50:19.000Z","dependencies_parsed_at":"2023-01-14T07:20:04.190Z","dependency_job_id":null,"html_url":"https://github.com/hatena/p5-Test-WWW-Stub","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/hatena/p5-Test-WWW-Stub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hatena%2Fp5-Test-WWW-Stub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hatena%2Fp5-Test-WWW-Stub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hatena%2Fp5-Test-WWW-Stub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hatena%2Fp5-Test-WWW-Stub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hatena","download_url":"https://codeload.github.com/hatena/p5-Test-WWW-Stub/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hatena%2Fp5-Test-WWW-Stub/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280878346,"owners_count":26406641,"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","status":"online","status_checked_at":"2025-10-24T02:00:06.418Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["perl","testing"],"created_at":"2024-11-06T19:44:43.935Z","updated_at":"2025-10-24T22:37:36.154Z","avatar_url":"https://github.com/hatena.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Actions Status](https://github.com/hatena/p5-Test-WWW-Stub/workflows/test/badge.svg)](https://github.com/hatena/p5-Test-WWW-Stub/actions)\n# NAME\n\nTest::WWW::Stub - Block and stub specified URL for LWP\n\n# SYNOPSIS\n\n    # External http(s) access via LWP is blocked by just declaring 'use Test::WWW::Stub';\n    # Note that 'require Test::WWW::Stub' or 'use Test::WWW::Stub ()' doesn't block external access.\n    use Test::WWW::Stub;\n\n    my $ua = LWP::UserAgent-\u003enew;\n\n    my $stubbed_res = [ 200, [], ['okay'] ];\n\n    {\n        my $guard = Test::WWW::Stub-\u003eregister(q\u003chttp://example.com/TEST\u003e, $stubbed_res);\n\n        is $ua-\u003eget('http://example.com/TEST')-\u003econtent, 'okay';\n    }\n    isnt $ua-\u003eget('http://example.com/TEST')-\u003econtent, 'okay';\n\n    {\n        # registering in void context doesn't create guard.\n        Test::WWW::Stub-\u003eregister(q\u003chttp://example.com/HOGE/\u003e, $stubbed_res);\n\n        is $ua-\u003eget('http://example.com/HOGE')-\u003econtent, 'okay';\n    }\n    is $ua-\u003eget('http://example.com/HOGE')-\u003econtent, 'okay';\n\n    {\n        # You can also use regexp for uri\n        my $guard = Test::WWW::Stub-\u003eregister(qr\u003c\\A\\Qhttp://example.com/MATCH/\\E\u003e, $stubbed_res);\n\n        is $ua-\u003eget('http://example.com/MATCH/hogehoge')-\u003econtent, 'okay';\n    }\n\n    {\n        # you can unstub and allow external access temporary\n        my $unstub_guard = Test::WWW::Stub-\u003eunstub;\n\n        # External access occurs!!\n        ok $ua-\u003eget('http://example.com');\n    }\n\n    my $last_req = Test::WWW::Stub-\u003elast_request; # Plack::Request\n    is $last_req-\u003euri, 'http://example.com/MATCH/hogehoge';\n\n    Test::WWW::Stub-\u003erequested_ok('GET', 'http://example.com/TEST'); # passes\n\n# DESCRIPTION\n\nTest::WWW::Stub is a helper module to block external http(s) request and stub some specific requests in your test.\n\nBecause this modules uses [LWP::Protocol::PSGI](https://metacpan.org/pod/LWP%3A%3AProtocol%3A%3APSGI) internally, you don't have to modify target codes using [LWP::UserAgent](https://metacpan.org/pod/LWP%3A%3AUserAgent).\n\n# METHODS\n\n- `register`\n\n        my $guard = Test::WWW::Stub-\u003eregister( $uri_or_re, $app_or_res );\n\n    Registers a new stub for URI `$uri_or_re`.\n    If called in void context, it simply registers the stub.\n    Otherwise,it returns a new guard which drops the stub on destroyed.\n\n    `$uri_or_re` is either an URI string or a compiled regular expression for URI.\n    `$app_or_res` is a PSGI response array ref, or a code ref which returns a PSGI response array ref.\n    If `$app_or_res` is a code ref, requests are passed to the code ref following syntax:\n\n        my $req = Plack::Request-\u003enew($env);\n        $app_or_res-\u003e($env, $req);\n\n    Once registered, `$app_or_res` will be return from LWP::UserAgent on requesting certain URI matches `$uri_or_re`.\n\n- `requested_ok`\n\n        Test::WWW::Stub-\u003erequested_ok($method, $uri);\n\n    Passes when `$uri` has been requested with `$method`, otherwise fails and dumps requests handled by Test::WWW::Stub.\n\n    This method calls `Test::More::ok` or `Test::More::diag` internally.\n\n- `requests`\n\n        my @requests = Test::WWW::Stub-\u003erequests;\n\n    Returns an array of [Plack::Request](https://metacpan.org/pod/Plack%3A%3ARequest) which is handled by Test::WWW::Stub.\n\n- `last_request`\n\n        my $last_req = Test::WWW::Stub-\u003elast_request;\n\n    Returns a Plack::Request object last handled by Test::WWW::Stub.\n\n    This method is same as `[Test::WWW::Stub-\u003erequests]-\u003e[-1]`.\n\n- `last_request_for`\n\n        my $last_req = Test::WWW::Stub-\u003elast_request_for($method, $uri);\n\n    Returns a `Plack::Request` object last handled by Test::WWW::Stub and matched given HTTP method and URI.\n\n- `clear_requests`\n\n        Test::WWW::Stub-\u003eclear_requests;\n\n    Clears request history of Test::WWW::Stub.\n\n    `[Test::WWW::Stub-\u003erequests]` becomes empty just after this method called.\n\n- `unstub`\n\n        my $unstub_guard = Test::WWW::Stub-\u003eunstub;\n\n    Unregister stub and enables external access, and returns a guard object which re-enables stub on destroyed.\n\n    In constrast to `register`, this method doesn't work when called in void context.\n\n- `import`\n\n        Test::WWW::Stub-\u003eimport(%options)\n        or\n        use Test:::WWW::Stub\n\n    This `%options` are equivalent to the options of `LWP::Protocol::PSGI-\u003eregister(%options)`. For example, the options can be set as follows:\n\n        use Test::WWW::Stub (\n            uri =\u003e sub {\n                my $uri = shift;\n                $uri ne 'http://localhost:9200'\n            }\n        );\n\n- `unimport`\n\n        Test::WWW::Stub-\u003eunimport\n        or\n        no Test::WWW::Stub;\n\n    Delete the stubbed app and stop stubbing. If you need to stub again, import Test::WWW::Stub.\n\n# LICENSE\n\nCopyright (C) Hatena Co., Ltd.\n\nThis library is free software; you can redistribute it and/or modify\nit under the same terms as Perl itself.\n\n# AUTHOR\n\nAsato Wakisaka \u003casato.wakisaka@gmail.com\u003e\n\nOriginal implementation written by suzak.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhatena%2Fp5-test-www-stub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhatena%2Fp5-test-www-stub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhatena%2Fp5-test-www-stub/lists"}