{"id":13683231,"url":"https://github.com/kfly8/p5-Function-Interface","last_synced_at":"2025-04-30T12:34:01.851Z","repository":{"id":34243518,"uuid":"172299554","full_name":"kfly8/p5-Function-Interface","owner":"kfly8","description":"Declare typed interface package","archived":false,"fork":false,"pushed_at":"2022-06-13T10:46:39.000Z","size":77,"stargazers_count":8,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-30T16:26:50.604Z","etag":null,"topics":["perl","perl5","perl5-module"],"latest_commit_sha":null,"homepage":"","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/kfly8.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":"2019-02-24T05:23:00.000Z","updated_at":"2023-06-17T00:55:54.000Z","dependencies_parsed_at":"2022-09-14T02:30:45.078Z","dependency_job_id":null,"html_url":"https://github.com/kfly8/p5-Function-Interface","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fp5-Function-Interface","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fp5-Function-Interface/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fp5-Function-Interface/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fp5-Function-Interface/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kfly8","download_url":"https://codeload.github.com/kfly8/p5-Function-Interface/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224212089,"owners_count":17274356,"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":["perl","perl5","perl5-module"],"created_at":"2024-08-02T13:02:04.829Z","updated_at":"2024-11-12T03:30:41.583Z","avatar_url":"https://github.com/kfly8.png","language":"Perl","funding_links":[],"categories":["Perl"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/kfly8/p5-Function-Interface.svg?branch=master)](https://travis-ci.org/kfly8/p5-Function-Interface) [![Coverage Status](https://img.shields.io/coveralls/kfly8/p5-Function-Interface/master.svg?style=flat)](https://coveralls.io/r/kfly8/p5-Function-Interface?branch=master) [![MetaCPAN Release](https://badge.fury.io/pl/Function-Interface.svg)](https://metacpan.org/release/Function-Interface)\n# NAME\n\nFunction::Interface - declare typed interface package\n\n# SYNOPSIS\n\nDeclare typed interface package `IFoo`:\n\n```perl\npackage IFoo {\n    use Function::Interface;\n    use Types::Standard -types;\n\n    fun hello(Str $msg) :Return(Str);\n\n    fun add(Int $a, Int $b) :Return(Int);\n}\n```\n\nImplements the interface package `IFoo`:\n\n```perl\npackage Foo {\n    use Function::Interface::Impl qw(IFoo);\n    use Types::Standard -types;\n\n    fun hello(Str $msg) :Return(Str) {\n        return \"HELLO $msg\";\n    }\n\n    fun add(Int $a, Int $b) :Return(Int) {\n        return $a + $b;\n    }\n}\n```\n\nUse the type `ImplOf`:\n\n```perl\npackage FooService {\n    use Function::Interface::Types qw(ImplOf);\n    use Function::Parameters;\n    use Function::Return;\n    use Mouse;\n\n    use aliased 'IFoo';\n\n    fun greet(ImplOf[IFoo] $foo) :Return() {\n        print $foo-\u003ehello;\n        return;\n    }\n}\n\nmy $foo_service = FooService-\u003enew;\nmy $foo = Foo-\u003enew; # implements of IFoo\n\n$foo_service-\u003egreet($foo);\n```\n\n# DESCRIPTION\n\nThis module provides a typed interface.\n`Function::Interface` declares abstract functions without implementation and defines an interface package.\n`Function::Interface::Impl` checks if the abstract functions are implemented at **compile time**.\n\n## SUPPORT\n\nThis module supports all perl versions starting from v5.14.\n\n## Declare function\n\n`Function::Interface` provides two new keywords, `fun` and `method`, for declaring abstract functions and methods with types:\n\n```\nfun hello(Str $msg) :Return(Str);\n\nmethod new(Num :$x, Num :$y) :Return(Point);\n```\n\nThe method of declaring abstract functions is the same as [Function::Parameters](https://metacpan.org/pod/Function::Parameters) and [Function::Return](https://metacpan.org/pod/Function::Return).\n\n### declare parameters\n\nFunction arguments must always specify a variable name and type constraint, and named arguments and optional arguments can optionally be specified:\n\n```perl\n# positional parameters\n# e.g. called `foo(1,2,3)`\nfun foo1(Int $a, Int $b, Int $c) :Return();\n\n# named parameters\n# e.g. called `bar(x =\u003e 123, y =\u003e 456)`\nfun foo2(Num :$x, Num :$y) :Return();\n\n# optional\n# e.g. called `baz()` or `baz('some')`\nfun foo3(Str $msg=) :Return();\n```\n\n### declare return types\n\nSpecify zero or more type constraints for the function's return value:\n\n```\n# zero(empty)\nfun bar1() :Return();\n\n# one\nfun bar2() :Return(Str);\n\n# two\nfun bar3() :Return(Str, Num);\n```\n\n## requirements of type constraint\n\nThe requirements of type constraint of `Function::Interface` is the same as for [Function::Parameters](https://metacpan.org/pod/Function::Parameters) and [Function::Return](https://metacpan.org/pod/Function::Return).\n\n# METHODS\n\n## Function::Interface::info($interface\\_package)\n\nThe function `Function::Interface::info` lets you introspect interface functions:\n\n```perl\n# declare interface package\npackage IBar {\n    use Function::Interface;\n    fun hello() :Return();\n    fun world() :Return();\n}\n\n# introspect\nmy $info = Function::Interface::info 'IBar';\n$info-\u003epackage; # =\u003e IBar\n$info-\u003efunctions; # =\u003e list of Function::Interface::Info::Function\n```\n\nIt returns either `undef` if it knows nothing about the interface or an object of [Function::Interface::Info](https://metacpan.org/pod/Function::Interface::Info).\n\n# SEE ALSO\n\n[Function::Interface::Impl](https://metacpan.org/pod/Function::Interface::Impl)\n\n# LICENSE\n\nCopyright (C) kfly8.\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\nkfly8 \u003ckfly@cpan.org\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkfly8%2Fp5-Function-Interface","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkfly8%2Fp5-Function-Interface","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkfly8%2Fp5-Function-Interface/lists"}