{"id":21651787,"url":"https://github.com/hoytech/method-cascade","last_synced_at":"2025-03-20T04:00:13.659Z","repository":{"id":16077698,"uuid":"18822206","full_name":"hoytech/Method-Cascade","owner":"hoytech","description":"Use method chaining with any API","archived":false,"fork":false,"pushed_at":"2014-04-18T18:15:40.000Z","size":156,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-25T05:43:00.101Z","etag":null,"topics":[],"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/hoytech.png","metadata":{"files":{"readme":"README.pod","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":"2014-04-16T01:15:23.000Z","updated_at":"2014-09-09T17:37:15.000Z","dependencies_parsed_at":"2022-09-11T15:30:15.592Z","dependency_job_id":null,"html_url":"https://github.com/hoytech/Method-Cascade","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/hoytech%2FMethod-Cascade","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoytech%2FMethod-Cascade/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoytech%2FMethod-Cascade/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoytech%2FMethod-Cascade/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoytech","download_url":"https://codeload.github.com/hoytech/Method-Cascade/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244547602,"owners_count":20470103,"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":[],"created_at":"2024-11-25T07:49:32.963Z","updated_at":"2025-03-20T04:00:13.584Z","avatar_url":"https://github.com/hoytech.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"=encoding utf-8\n\n=head1 NAME\n\nMethod::Cascade - Use method chaining with any API\n\n=head1 SYNOPSIS\n\n    use Method::Cascade;\n    use IO::Socket::INET;\n\n    cascade(IO::Socket::INET-\u003enew('google.com:http'))\n      -\u003etimeout(5)\n      -\u003esetsockopt(SOL_SOCKET, SO_KEEPALIVE, pack(\"l\", 1))\n      -\u003eprint(\"GET / HTTP/1.0\\r\\n\\r\\n\")\n      -\u003erecv(my $response, 4096);\n\n    print $response;\n\n\n=head1 BACKGROUND\n\nMethod chaining is a very intuitive and convenient way to make sequential method calls on the same object.\n\nUnfortunately, not all APIs support method chaining. In order for an API to be chainable, every method must return C\u003c$self\u003e. However often there are good reasons for an API to not return C\u003c$self\u003e. For instance, it can be useful for setter methods to return the previous values.\n\nMethod cascading is a feature borrowed from Smalltalk. Its advantage is that any API can be used in a chained fashion, even if the designers didn't plan or intend for it to be chainable. You, the user of the API, can choose if you care about the return values and, if not, go ahead and cascade method calls.\n\n\n=head1 DESCRIPTION\n\nThis module exports one function: C\u003ccascade\u003e. You should pass it the object that you would like to chain/cascade method calls on. It will return a wrapper object that forwards all method calls to the object you passed in. After forwarding, it returns the same wrapper object.\n\nBecause return values are ignored (the methods are in fact called in void context), method cascading is most useful when used with APIs that throw exceptions instead of returning error values. For instance, with L\u003cDBI\u003e, as long as C\u003cRaiseError\u003e is true and C\u003cAutoCommit\u003e is false you can safely do the following:\n\n    cascade($dbh)-\u003edo(\"INSERT INTO admins (name) VALUES (?)\", undef, $user)\n                 -\u003edo(\"DELETE FROM users WHERE name=?\", undef, $user)\n                 -\u003ecommit;\n\n\n\n=head1 OTHER LANGUAGES\n\nAs mentioned, method cascading was first invented in Smalltalk.\n\nL\u003cDart|https://www.dartlang.org/\u003e is a web-language that has also added this feature. In Dart, the C\u003c..\u003e operator is a method cascading operator that returns the object the method was invoked on instead of the method call result. Here is a Dart example:\n\n    myTokenTable\n      ..add(\"aToken\")\n      ..add(\"anotherToken\")\n      // and on and on\n      ..add(\"theUmpteenthToken\");\n\n\n\n=head1 SEE ALSO\n\nL\u003cThe Method::Cascade github repo|https://github.com/hoytech/Method-Cascade\u003e\n\nL\u003cMethod Cascades in Dart|http://news.dartlang.org/2012/02/method-cascades-in-dart-posted-by-gilad.html\u003e\n\nL\u003cWikipedia entry|https://en.wikipedia.org/wiki/Method_cascading\u003e\n\n\n=head1 AUTHOR\n\nDoug Hoyte, C\u003c\u003c \u003cdoug@hcsw.org\u003e \u003e\u003e\n\nThanks to Richard Farr for helping me come up with this idea (during a conversation about C++ smart pointers).\n\n\n=head1 COPYRIGHT \u0026 LICENSE\n\nCopyright 2014 Doug Hoyte.\n\nThis module is licensed under the same terms as perl itself.\n\n\n=cut\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoytech%2Fmethod-cascade","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoytech%2Fmethod-cascade","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoytech%2Fmethod-cascade/lists"}