{"id":19877455,"url":"https://github.com/mla/router-right","last_synced_at":"2025-05-02T12:30:49.598Z","repository":{"id":66616598,"uuid":"64871893","full_name":"mla/router-right","owner":"mla","description":"Perl-based, framework-agnostic URL routing engine for web applications","archived":false,"fork":false,"pushed_at":"2024-03-03T17:45:52.000Z","size":111,"stargazers_count":3,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-07T01:23:29.689Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/mla.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-03T19:01:30.000Z","updated_at":"2024-03-04T12:56:58.000Z","dependencies_parsed_at":"2024-03-03T18:44:15.337Z","dependency_job_id":null,"html_url":"https://github.com/mla/router-right","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/mla%2Frouter-right","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mla%2Frouter-right/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mla%2Frouter-right/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mla%2Frouter-right/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mla","download_url":"https://codeload.github.com/mla/router-right/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252038097,"owners_count":21684624,"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-12T16:37:30.010Z","updated_at":"2025-05-02T12:30:49.332Z","avatar_url":"https://github.com/mla.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SYNOPSIS\n\n    use Router::Right;\n\n    my $r = Router::Right-\u003enew;\n\n    $r-\u003eadd(home =\u003e '/', 'Home#show');\n    $r-\u003eadd(blog =\u003e '/blog/{year}/{month}', 'Blog#monthly');\n\n    my $match = $r-\u003ematch('/blog/1916/08'); \n\n    # Returns {\n    #   controller =\u003e 'Blog',\n    #   action =\u003e 'monthly',\n    #   year =\u003e '1916',\n    #   month =\u003e '08',\n    # }\n\n# DESCRIPTION\n\nRouter::Right is a Perl5-based, framework-agnostic routing engine used to\nmap web application request URLs to application handlers.\n\n# METHODS\n\n- new()\n\n    Returns a new Router::Right instance\n\n- add($name =\u003e $route\\_path, \\\\%payload \\[, %options\\])\n\n    Define a route. $name is used to reference the route elsewhere. On a successful match, the payload hash reference is returned; by convention, a payload includes \"controller\" and \"action\" values. For example:\n\n        $r-\u003eadd(entries =\u003e '/entries', { controller =\u003e 'Entries', action =\u003e 'show' })\n\n    See the ROUTE DEFINITION section for details on how $route\\_path values are specified.\n\n    Also, if the payload consists solely of controller and action values, it can be specified as a string in the format \"controller#action\". For example:\n\n        $r-\u003eadd(entries =\u003e '/entries', 'Entries#show')\n\n    is exactly equivalent to specifying a payload of: { controller =\u003e 'Entries', action =\u003e 'show' }.\n\n    By default, routes match any HTTP request method (e.g., GET, POST). To restrict them, supply a \"methods\" option. e.g.,\n\n        $r-\u003eadd(entries =\u003e '/entries', 'Entries#show', methods =\u003e 'GET')\n\n    That would only match GET requests. The value may be either a string or an array reference of\n    strings. e.g.,\n\n        $r-\u003eadd(entries =\u003e '/entries', 'Entries#show', methods =\u003e [qw/ GET POST /])\n\n    Method strings are case-insensitive. As a convenience, the allowed methods can also be specified\n    as part of the route path itself. e.g.,\n\n        $r-\u003eadd(entries =\u003e 'GET|POST /entries', 'Entries#show')\n\n- match($url \\[, $method\\])\n\n    Attempts to find a route that matches the supplied $url. Routes are matched in the order defined.\n\n    If a match is found, its associated payload is returned. If not, undef is returned and the error() method will indicate why the match failed.\n\n    $method, if supplied, is the HTTP method of the request (e.g., GET, POST, etc.). Specifying $method may prevent a route from otherwise matching if the route was defined with a restricted set of allowed methods (see ROUTE DEFINITION). By default, all request methods are allowed.\n\n    While the payload is always a hash reference, starting with version 1.05,\n    it is also blessed into the Router::Right::Match class, which provides\n    access to the route definition that resulted in the match.\n\n- error()\n\n    Returns the error code of the last failed match.\n\n        404 = no match found\n        405 = method not allowed\n\n    A 405 result indicates a match was found, but the request method was not allowed. allowed\\_methods() can be called to obtain a list of the methods that are permitted for the route.\n\n    The above error codes are also available as symbolic constants through the NOT\\_FOUND and\n    METHOD\\_NOT\\_ALLOWED functions.\n\n- allowed\\_methods(\\[ $name \\])\n\n    Returns the list of allowed methods for a given route name or path. In list context, returns a list. In scalar context, returns an array reference. An empty list/array indicates that all methods are\n    permitted.\n\n    If route $name is supplied, returns its permitted methods. Returns undef in scalar context if the route is unknown. If $name contains a forward slash, it's intepreted as a route path, instead.\n\n    With no argument, returns the methods permitted by the last match() attempt. Returns undef in scalar context if there was no prior match.\n\n        $r-\u003eadd(entries =\u003e 'PUT|GET /entries', { controller =\u003e 'Entries' });\n        print join(', ', $r-\u003eallowed_methods('entries')), \"\\n\"; # prints GET, PUT\n\n- url($name \\[, %params\\])\n\n    Constructs a URL from the $name route. Placeholder values are supplied as %params. Unknown placeholder values are appended as query string parameters.\n\n    Example:\n\n        $r-\u003eadd(entry =\u003e '/entries/{year}', { controller =\u003e 'Entry' });\n        $r-\u003eurl('entry', year =\u003e '1916', q =\u003e 'abc'); # produces /entries/1916?q=abc \n\n    The return value is a [URI](https://metacpan.org/pod/URI) instance.\n\n- as\\_string()\n\n    Returns a report of the defined routes, in order of definition.\n\n- with($name =\u003e $route\\_path \\[, %options\\]\n\n    Helper method to share information across multiple routes. For example:\n\n        $r-\u003ewith(admin =\u003e '/admin',        'Admin')\n          -\u003eadd(users  =\u003e '/users',        '#users')\n          -\u003eadd(trx    =\u003e '/transactions', '#transactions')\n        ;\n\n        print $r-\u003eas_string;\n\n        # prints:\n        #   admin_users * /admin/users        { action =\u003e \"users\", controller =\u003e \"Admin\" }\n        #   admin_trx   * /admin/transactions { action =\u003e \"transactions\", controller =\u003e \"Admin\" }\n\n    The payload contents are merged. The route names are joined by an underscore. The paths are concatenated. Either or both of $name and $route\\_path may be undefined.\n\n    If a nested route specifies a controller beginning with '::', it is concatenated with\n    the outer controller name. For example:\n\n        $r-\u003ewith(admin =\u003e '/admin', 'Admin')\n          -\u003eadd(users  =\u003e '/users', '::User#show')\n        ;\n\n        print $r-\u003eas_string;\n\n        # prints:\n        #   admin_users * /admin/users { action =\u003e \"show\", controller =\u003e \"Admin::User\" }\n\n    A callback is accepted, which allows chaining with() calls:\n\n        $r-\u003ewith(admin =\u003e '/admin',  { controller =\u003e 'Admin' }, call =\u003e sub {\n          $_-\u003eadd(users =\u003e '/users', { action =\u003e 'users' });\n          $_-\u003eadd(log   =\u003e '/log',   { action =\u003e 'log' });\n        })-\u003ewith(dashboard =\u003e '/dashboard', { controller =\u003e 'Admin::Dashboard' }, call =\u003e sub {\n          $_-\u003eadd(view =\u003e '/{action}');\n        });\n\n        print $r-\u003eas_string;\n\n        # prints:\n        #   admin_users          * /admin/users\n        #   admin_log            * /admin/log\n        #   admin_dashboard_view * /admin/dashboard/{action}\n\n    Within the callback function, $\\_ is set to the router instance. It is also supplied as a parameter.\n\n- resource($name, \\\\%payload \\[, %options\\])\n\n    Adds routes to create, read, update, and delete a given resource. For example:\n\n        my $r = Router::Right-\u003enew-\u003eresource('message', { controller =\u003e 'Message' });\n        print $r-\u003eas_string, \"\\n\";\n\n        # prints:\n        #                 messages GET    /messages{.format}           { action =\u003e \"index\", controller =\u003e \"Message\" }\n        #                          POST   /messages{.format}           { action =\u003e \"create\", controller =\u003e \"Message\" }\n        #       formatted_messages GET    /messages.{format}           { action =\u003e \"index\", controller =\u003e \"Message\" }\n        #              new_message GET    /messages/new{.format}       { action =\u003e \"new\", controller =\u003e \"Message\" }\n        #    formatted_new_message GET    /messages/new.{format}       { action =\u003e \"new\", controller =\u003e \"Message\" }\n        #                  message GET    /messages/{id}{.format}      { action =\u003e \"show\", controller =\u003e \"Message\" }\n        #                          PUT    /messages/{id}{.format}      { action =\u003e \"update\", controller =\u003e \"Message\" }\n        #                          DELETE /messages/{id}{.format}      { action =\u003e \"delete\", controller =\u003e \"Message\" }\n        #        formatted_message GET    /messages/{id}.{format}      { action =\u003e \"show\", controller =\u003e \"Message\" }\n        #             edit_message GET    /messages/{id}{.format}/edit { action =\u003e \"edit\", controller =\u003e \"Message\" }\n        #   formatted_edit_message GET    /messages/{id}.{format}/edit { action =\u003e \"edit\", controller =\u003e \"Message\" }\n\n# ROUTE DEFINITION\n\nA route path is a normal URL path with the addition of placeholder variables. For example:\n\n    $r-\u003eadd(entries =\u003e '/entries/{year}/{month}');\n\ndefines a route path containing two placeholders, \"year\" and \"month'. By default, a placeholder matches any string up to the next forward slash.\n\nPlaceholder names must not begin with a number, nor contain hyphens or forward slashes.\n\nThe default match rule may be overridden. For example:\n\n    $r-\u003eadd(entries =\u003e '/entries/{year:\\d+}/{month:\\d+}');\n\nis the same as above, except it will only match if both the year and month contain only digits.\n\nThe special {.format} placeholder can be used to allow an optional file extension to be appended. For example:\n\n    $r-\u003eadd(download =\u003e '/dl/{file}{.format}', { controller =\u003e 'Download' });\n    $r-\u003ematch('/dl/foo.gz'); # returns { controller =\u003e 'Download', file =\u003e 'foo', format =\u003e 'gz' }\n    $r-\u003ematch('/dl/foo');    # returns { controller =\u003e 'Download', file =\u003e 'foo' }\n\n    # And to build a URL from it:\n    $r-\u003eurl('download', file =\u003e 'foo', format =\u003e 'bz2'); # /dl/foo.bz2\n\n# SEE ALSO\n\nRouter::Right is based on Tokuhiro Matsuno's Router::Simple and Router::Boom modules.\n\nThis module seeks to implement most features of Python's Routes:\n[https://routes.readthedocs.io/en/latest/index.html](https://routes.readthedocs.io/en/latest/index.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmla%2Frouter-right","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmla%2Frouter-right","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmla%2Frouter-right/lists"}