{"id":18981403,"url":"https://github.com/awncorp/rewire","last_synced_at":"2026-06-14T20:34:16.574Z","repository":{"id":55015298,"uuid":"300957313","full_name":"awncorp/rewire","owner":"awncorp","description":"Dependency Injection Container for Perl 5","archived":false,"fork":false,"pushed_at":"2021-01-15T04:37:30.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-10T20:08:23.392Z","etag":null,"topics":["dependency-injection","perl","perl5"],"latest_commit_sha":null,"homepage":"https://metacpan.org/release/Rewire","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/awncorp.png","metadata":{"files":{"readme":"README","changelog":"CHANGES","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-03T19:06:34.000Z","updated_at":"2022-07-24T21:01:09.000Z","dependencies_parsed_at":"2022-08-14T09:10:20.785Z","dependency_job_id":null,"html_url":"https://github.com/awncorp/rewire","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/awncorp/rewire","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awncorp%2Frewire","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awncorp%2Frewire/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awncorp%2Frewire/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awncorp%2Frewire/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/awncorp","download_url":"https://codeload.github.com/awncorp/rewire/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awncorp%2Frewire/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34337551,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"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":["dependency-injection","perl","perl5"],"created_at":"2024-11-08T16:09:45.007Z","updated_at":"2026-06-14T20:34:16.559Z","avatar_url":"https://github.com/awncorp.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"NAME\n\n    Rewire - Dependency Injection\n\nABSTRACT\n\n    Dependency Injection Container for Perl 5\n\nSYNOPSIS\n\n      use Rewire;\n    \n      my $services = {\n        filetemp =\u003e {\n          package =\u003e 'File/Temp'\n        },\n        tempfile =\u003e {\n          package =\u003e 'Mojo/File',\n          argument =\u003e { '$service' =\u003e 'filetemp' }\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(services =\u003e $services);\n    \n      $rewire-\u003eresolve('tempfile');\n\nDESCRIPTION\n\n    This package provides methods for using dependency injection, and\n    building objects and values.\n\nINTEGRATES\n\n    This package integrates behaviors from:\n\n    Data::Object::Role::Buildable\n\n    Data::Object::Role::Proxyable\n\nLIBRARIES\n\n    This package uses type constraints from:\n\n    Types::Standard\n\nSCENARIOS\n\n    This package supports the following scenarios:\n\n $callback\n\n      use Rewire;\n    \n      my $services = {\n        io =\u003e {\n          package =\u003e 'IO/Handle'\n        },\n        log =\u003e {\n          package =\u003e 'Mojo/Log',\n          argument =\u003e {\n            format =\u003e { '$callback' =\u003e 'io' }\n          }\n        },\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services\n      );\n\n    This package supports resolving services as callbacks to be passed\n    around and/or resolved by other services. The $callback directive is\n    used to specify the name of a service to be resolved and passed as an\n    argument.\n\n $envvar\n\n      use Rewire;\n    \n      my $services = {\n        file =\u003e {\n          package =\u003e 'Mojo/File',\n          argument =\u003e { '$envvar' =\u003e 'home' }\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services\n      );\n\n    This package supports inlining environment variables as arguments to\n    services. The $envvar directive is used to specify the name of an\n    environment variable, and can also be used in metadata for reusability.\n\n $function\n\n      use Rewire;\n    \n      my $services = {\n        temp =\u003e {\n          package =\u003e 'File/Temp'\n        },\n        file =\u003e {\n          package =\u003e 'Mojo/File',\n          argument =\u003e { '$function' =\u003e 'temp#tempfile' }\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services\n      );\n\n    This package supports inlining the result of a service resolution and\n    function call as arguments to services. The # delimited $function\n    directive is used to specify the name of an existing service on the\n    right-hand side, and an arbitrary function to be call on the result on\n    the left-hand side.\n\n $metadata\n\n      use Rewire;\n    \n      my $metadata = {\n        home =\u003e '/home/ubuntu'\n      };\n    \n      my $services = {\n        file =\u003e {\n          package =\u003e 'Mojo/File',\n          argument =\u003e { '$metadata' =\u003e 'home' }\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        metadata =\u003e $metadata,\n        services =\u003e $services\n      );\n\n    This package supports inlining configuration data as arguments to\n    services. The $metadata directive is used to specify the name of a\n    stashed configuration value or data structure.\n\n $method\n\n      use Rewire;\n    \n      my $services = {\n        temp =\u003e {\n          package =\u003e 'File/Temp'\n        },\n        file =\u003e {\n          package =\u003e 'Mojo/File',\n          argument =\u003e { '$method' =\u003e 'temp#filename' }\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services\n      );\n\n    This package supports inlining the result of a service resolution and\n    method call as arguments to services. The # delimited $method directive\n    is used to specify the name of an existing service on the right-hand\n    side, and an arbitrary method to be call on the result on the left-hand\n    side.\n\n $routine\n\n      use Rewire;\n    \n      my $services = {\n        temp =\u003e {\n          package =\u003e 'File/Temp'\n        },\n        file =\u003e {\n          package =\u003e 'Mojo/File',\n          argument =\u003e { '$routine' =\u003e 'temp#tempfile' }\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services\n      );\n\n    This package supports inlining the result of a service resolution and\n    routine call as arguments to services. The # delimited $routine\n    directive is used to specify the name of an existing service on the\n    right-hand side, and an arbitrary routine to be call on the result on\n    the left-hand side.\n\n $service\n\n      use Rewire;\n    \n      my $services = {\n        io =\u003e {\n          package =\u003e 'IO/Handle'\n        },\n        log =\u003e {\n          package =\u003e 'Mojo/Log',\n          argument =\u003e {\n            handle =\u003e { '$service' =\u003e 'io' }\n          }\n        },\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services\n      );\n\n    This package supports inlining resolved services as arguments to other\n    services. The $service directive is used to specify the name of a\n    service to be resolved and passed as an argument.\n\n arguments\n\n      use Rewire;\n    \n      my $metadata = {\n        applog =\u003e '/var/log/rewire.log'\n      };\n    \n      my $services = {\n        mojo_log =\u003e {\n          package =\u003e 'Mojo/Log',\n          argument =\u003e {\n            path =\u003e { '$metadata' =\u003e 'applog' },\n            level =\u003e 'warn'\n          },\n          argument_as =\u003e 'list'\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services,\n        metadata =\u003e $metadata\n      );\n\n    This package supports providing static and/or dynamic arguments during\n    object construction from metadata or other services.\n\n builder\n\n      use Rewire;\n    \n      my $services = {\n        mojo_date =\u003e {\n          package =\u003e 'Mojo/Date',\n          builder =\u003e [\n            {\n              method =\u003e 'new',\n              return =\u003e 'self'\n            },\n            {\n              method =\u003e 'to_datetime',\n              return =\u003e 'result'\n            }\n          ]\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services,\n      );\n\n    This package supports specifying multiple build steps as function,\n    method, and routine calls and chaining them together.\n\n config\n\n      use Rewire;\n    \n      my $metadata = {\n        home =\u003e '/home/ubuntu'\n      };\n    \n      my $services = {\n        tempfile =\u003e {\n          package =\u003e 'Mojo/File',\n          argument =\u003e { '$metadata' =\u003e 'home' }\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services,\n        metadata =\u003e $metadata\n      );\n\n    This package supports configuring services and metadata in the service\n    of building objects and values.\n\n constructor\n\n      use Rewire;\n    \n      my $services = {\n        mojo_date =\u003e {\n          package =\u003e 'Mojo/Date',\n          constructor =\u003e 'new'\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services\n      );\n\n    This package supports specifying constructors other than the\n    traditional new routine. A constructor is always called with the\n    package name as the invocant.\n\n extends\n\n      use Rewire;\n    \n      my $services = {\n        io =\u003e {\n          package =\u003e 'IO/Handle'\n        },\n        log =\u003e {\n          package =\u003e 'Mojo/Log',\n          argument =\u003e {\n            handle =\u003e { '$service' =\u003e 'io' }\n          }\n        },\n        development_log =\u003e {\n          package =\u003e 'Mojo/Log',\n          extends =\u003e 'log',\n          builder =\u003e [\n            {\n              method =\u003e 'new',\n              return =\u003e 'self'\n            },\n            {\n              method =\u003e 'path',\n              argument =\u003e '/tmp/development.log',\n              return =\u003e 'none'\n            },\n            {\n              method =\u003e 'level',\n              argument =\u003e 'debug',\n              return =\u003e 'none'\n            }\n          ]\n        },\n        production_log =\u003e {\n          package =\u003e 'Mojo/Log',\n          extends =\u003e 'log',\n          builder =\u003e [\n            {\n              method =\u003e 'new',\n              return =\u003e 'self'\n            },\n            {\n              method =\u003e 'path',\n              argument =\u003e '/tmp/production.log',\n              return =\u003e 'none'\n            },\n            {\n              method =\u003e 'level',\n              argument =\u003e 'warn',\n              return =\u003e 'none'\n            }\n          ]\n        },\n        staging_log =\u003e {\n          package =\u003e 'Mojo/Log',\n          extends =\u003e 'development_log',\n        },\n        testing_log =\u003e {\n          package =\u003e 'Mojo/Log',\n          extends =\u003e 'log',\n        },\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services\n      );\n\n    This package supports extending services in the definition of other\n    services, recursively compiling service configurations and eventually\n    executing the requested compiled service.\n\n function\n\n      use Rewire;\n    \n      my $services = {\n        foo_sum =\u003e {\n          package =\u003e 'Mojo/Util',\n          function =\u003e 'md5_sum',\n          argument =\u003e 'foo',\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services,\n      );\n\n    This package supports specifying construction as a function call, which\n    when called does not provide an invocant.\n\n lifecycle\n\n      use Rewire;\n    \n      my $metadata = {\n        home =\u003e '/home/ubuntu'\n      };\n    \n      my $services = {\n        tempfile =\u003e {\n          package =\u003e 'Mojo/File',\n          argument =\u003e { '$metadata' =\u003e 'home' },\n          lifecycle =\u003e 'singleton'\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services,\n        metadata =\u003e $metadata\n      );\n\n    This package supports different lifecycle options which determine when\n    services are built and whether they're persisted.\n\n metadata\n\n      use Rewire;\n    \n      my $metadata = {\n        homedir =\u003e '/home',\n        tempdir =\u003e '/tmp'\n      };\n    \n      my $services = {\n        home =\u003e {\n          package =\u003e 'Mojo/Path',\n          argument =\u003e { '$metadata' =\u003e 'homedir' },\n        },\n        temp =\u003e {\n          package =\u003e 'Mojo/Path',\n          argument =\u003e { '$metadata' =\u003e 'tempdir' },\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services,\n        metadata =\u003e $metadata\n      );\n\n    This package supports specifying data and structures which can be used\n    in the construction of multiple services.\n\n method\n\n      use Rewire;\n    \n      my $services = {\n        mojo_url =\u003e {\n          package =\u003e 'Mojo/URL',\n          argument =\u003e 'https://perl.org',\n          method =\u003e 'new'\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services,\n      );\n\n    This package supports specifying construction as a method call, which\n    when called provides the package or object instance as the invocant.\n\n proxyable\n\n      use Rewire;\n    \n      my $services = {\n        home =\u003e {\n          package =\u003e 'Mojo/Path',\n          argument =\u003e '/home',\n        },\n        temp =\u003e {\n          package =\u003e 'Mojo/Path',\n          argument =\u003e '/tmp',\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services\n      );\n    \n      # resolve services via method calls\n      [\n        $rewire-\u003ehome, # i.e. $rewire-\u003eprocess('home')\n        $rewire-\u003etemp  # i.e. $rewire-\u003eprocess('temp')\n      ]\n\n    This package supports the resolution of services using a single method\n    call. This is enabled by intercepting method calls and proxying them to\n    the \"process\" method.\n\n routine\n\n      use Rewire;\n    \n      my $services = {\n        mojo_url =\u003e {\n          package =\u003e 'Mojo/URL',\n          argument =\u003e 'https://perl.org',\n          routine =\u003e 'new'\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services,\n      );\n\n    This package supports specifying construction as a function call, which\n    when called provides the package as the invocant.\n\n service\n\n      my $metadata = {\n        home =\u003e '/home/ubuntu'\n      };\n    \n      my $services = {\n        tempfile =\u003e {\n          package =\u003e 'Mojo/File',\n          argument =\u003e { '$metadata' =\u003e 'home' },\n          lifecycle =\u003e 'eager'\n        }\n      };\n    \n      my $rewire = Rewire-\u003enew(\n        services =\u003e $services,\n        metadata =\u003e $metadata\n      );\n\n    This package supports defining services to be constructed on-demand or\n    automatically on instantiation.\n\nATTRIBUTES\n\n    This package has the following attributes:\n\n context\n\n      context(CodeRef)\n\n    This attribute is read-only, accepts (CodeRef) values, and is optional.\n\n engine\n\n      engine(InstanceOf[\"Data::Object::Space\"])\n\n    This attribute is read-only, accepts\n    (InstanceOf[\"Data::Object::Space\"]) values, and is optional.\n\n metadata\n\n      metadata(HashRef)\n\n    This attribute is read-only, accepts (HashRef) values, and is optional.\n\n services\n\n      services(HashRef)\n\n    This attribute is read-only, accepts (HashRef) values, and is optional.\n\nMETHODS\n\n    This package implements the following methods:\n\n config\n\n      config() : HashRef\n\n    The config method returns the configuration based on the services and\n    metadata attributes.\n\n    config example #1\n\n        # given: synopsis\n      \n        $rewire-\u003econfig;\n\n process\n\n      process(Str $name, Any $argument, Maybe[Str] $argument_as) : Any\n\n    The process method processes and returns an object or value based on\n    the service named but where the arguments are provided ad-hoc. Note:\n    This method is meant to be used to construct services ad-hoc and as\n    such bypasses caching and lifecycle effects.\n\n    process example #1\n\n        # given: synopsis\n      \n        $rewire-\u003eprocess('tempfile', 'rewire.tmp');\n\n    process example #2\n\n        use Rewire;\n      \n        my $metadata = {\n          logfile =\u003e '/var/log/rewire.log',\n        };\n      \n        my $services = {\n          mojo_log =\u003e {\n            package =\u003e 'Mojo/Log',\n            argument =\u003e { '$metadata' =\u003e 'logfile' },\n          }\n        };\n      \n        my $rewire = Rewire-\u003enew(\n          services =\u003e $services,\n          metadata =\u003e $metadata\n        );\n      \n        $rewire-\u003eprocess('mojo_log', {\n          level =\u003e 'fatal',\n          path =\u003e { '$metadata' =\u003e 'logfile' }\n        });\n\n    process example #3\n\n        use Rewire;\n      \n        my $metadata = {\n          logfile =\u003e '/var/log/rewire.log',\n        };\n      \n        my $services = {\n          mojo_log =\u003e {\n            package =\u003e 'Mojo/Log',\n            builder =\u003e [\n              {\n                method =\u003e 'new',\n                return =\u003e 'self'\n              }\n            ]\n          }\n        };\n      \n        my $rewire = Rewire-\u003enew(\n          services =\u003e $services,\n          metadata =\u003e $metadata\n        );\n      \n        $rewire-\u003eprocess('mojo_log', {\n          level =\u003e 'fatal',\n          path =\u003e { '$metadata' =\u003e 'logfile' }\n        });\n\n resolve\n\n      resolve(Str $name) : Any\n\n    The resolve method resolves and returns an object or value based on the\n    service named. Note: This method is recommended to be used to construct\n    services as defined by the configuration and as such doesn't not allow\n    passing additional arguments.\n\n    resolve example #1\n\n        # given: synopsis\n      \n        $rewire-\u003eresolve('tempfile');\n\n    resolve example #2\n\n        use Rewire;\n      \n        my $services = {\n          mojo_log =\u003e {\n            package =\u003e 'Mojo/Log',\n            argument =\u003e {\n              level =\u003e 'fatal',\n              path =\u003e '/var/log/rewire.log'\n            },\n          }\n        };\n      \n        my $rewire = Rewire-\u003enew(\n          services =\u003e $services,\n        );\n      \n        $rewire-\u003eresolve('mojo_log');\n\n    resolve example #3\n\n        package Dynamic;\n      \n        sub import;\n      \n        sub AUTOLOAD {\n          bless {};\n        }\n      \n        sub DESTROY {\n          ; # noop\n        }\n      \n        package main;\n      \n        use Rewire;\n      \n        my $services = {\n          dynamic =\u003e {\n            package =\u003e 'Dynamic',\n            builder =\u003e [\n              {\n                method =\u003e 'new',\n                return =\u003e 'self'\n              },\n              {\n                method =\u003e 'missing_method',\n                return =\u003e 'result'\n              }\n            ],\n          }\n        };\n      \n        my $rewire = Rewire-\u003enew(\n          services =\u003e $services,\n        );\n      \n        $rewire-\u003eresolve('dynamic');\n\n validate\n\n      validate() : Object\n\n    The validate method validates the configuration and throws an exception\n    if invalid, otherwise returns itself.\n\n    validate example #1\n\n        # given: synopsis\n      \n        $rewire-\u003evalidate;\n\nAUTHOR\n\n    Al Newkirk, awncorp@cpan.org\n\nLICENSE\n\n    Copyright (C) 2011-2019, Al Newkirk, et al.\n\n    This is free software; you can redistribute it and/or modify it under\n    the terms of the The Apache License, Version 2.0, as elucidated in the\n    \"license file\" \u003chttps://github.com/cpanery/rewire/blob/master/LICENSE\u003e.\n\nPROJECT\n\n    Wiki \u003chttps://github.com/cpanery/rewire/wiki\u003e\n\n    Project \u003chttps://github.com/cpanery/rewire\u003e\n\n    Initiatives \u003chttps://github.com/cpanery/rewire/projects\u003e\n\n    Milestones \u003chttps://github.com/cpanery/rewire/milestones\u003e\n\n    Contributing\n    \u003chttps://github.com/cpanery/rewire/blob/master/CONTRIBUTE.md\u003e\n\n    Issues \u003chttps://github.com/cpanery/rewire/issues\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawncorp%2Frewire","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawncorp%2Frewire","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawncorp%2Frewire/lists"}