{"id":15062314,"url":"https://github.com/avkhozov/mojolicious-plugin-model","last_synced_at":"2025-07-12T20:31:52.978Z","repository":{"id":27764525,"uuid":"31252792","full_name":"avkhozov/Mojolicious-Plugin-Model","owner":"avkhozov","description":"Mojolicious-Plugin-Model","archived":false,"fork":false,"pushed_at":"2021-07-12T15:35:01.000Z","size":59,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-22T03:06:35.394Z","etag":null,"topics":["perl"],"latest_commit_sha":null,"homepage":"https://metacpan.org/release/Mojolicious-Plugin-Model","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/avkhozov.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-24T09:24:32.000Z","updated_at":"2021-07-12T15:35:00.000Z","dependencies_parsed_at":"2022-09-10T01:10:46.194Z","dependency_job_id":null,"html_url":"https://github.com/avkhozov/Mojolicious-Plugin-Model","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avkhozov%2FMojolicious-Plugin-Model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avkhozov%2FMojolicious-Plugin-Model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avkhozov%2FMojolicious-Plugin-Model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avkhozov%2FMojolicious-Plugin-Model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avkhozov","download_url":"https://codeload.github.com/avkhozov/Mojolicious-Plugin-Model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225834367,"owners_count":17531470,"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"],"created_at":"2024-09-24T23:34:17.513Z","updated_at":"2024-11-22T03:06:38.888Z","avatar_url":"https://github.com/avkhozov.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nMojolicious::Plugin::Model - Model for Mojolicious applications\n\n# SYNOPSIS\n\nModel Users\n\n    package MyApp::Model::Users;\n    use Mojo::Base 'MojoX::Model';\n\n    sub check {\n      my ($self, $name, $pass) = @_;\n\n      # Constant\n      return int rand 2;\n\n      # Or Mojo::Pg\n      return $self-\u003eapp-\u003epg-\u003edb-\u003equery('...')-\u003earray-\u003e[0];\n\n      # Or HTTP check\n      return $self-\u003eapp-\u003eua-\u003epost($url =\u003e json =\u003e {user =\u003e $name, pass =\u003e $pass})\n        -\u003eres-\u003etx-\u003ejson('/result');\n    }\n\n    1;\n\nModel Users-Client\n\n    package MyApp::Model::Users::Client;\n    use Mojo::Base 'MyApp::Model::User';\n\n    sub do {\n      my ($self) = @_;\n    }\n\n    1;\n\nMojolicious::Lite application\n\n    #!/usr/bin/env perl\n    use Mojolicious::Lite;\n\n    use lib 'lib';\n\n    plugin 'Model';\n\n    # /?user=sebastian\u0026pass=secr3t\n    any '/' =\u003e sub {\n      my $c = shift;\n\n      my $user = $c-\u003eparam('user') || '';\n      my $pass = $c-\u003eparam('pass') || '';\n\n      # client model\n      my $client = $c-\u003emodel('users-client');\n      $client-\u003edo();\n\n      return $c-\u003erender(text =\u003e \"Welcome $user.\") if $c-\u003emodel('users')-\u003echeck($user, $pass);\n      $c-\u003erender(text =\u003e 'Wrong username or password.');\n    };\n\n    app-\u003estart;\n\nAll available options\n\n    #!/usr/bin/env perl\n    use Mojolicious::Lite;\n\n    plugin Model =\u003e {\n      namespaces   =\u003e ['MyApp::Model', 'MyApp::CLI::Model'],\n      base_classes =\u003e ['MyApp::Model'],\n      default      =\u003e 'MyApp::Model::Pg',\n      params =\u003e {Pg =\u003e {uri =\u003e 'postgresql://user@/mydb'}}\n    };\n\n# DESCRIPTION\n\n[Mojolicious::Plugin::Model](https://metacpan.org/pod/Mojolicious%3A%3APlugin%3A%3AModel) is a Model (M in MVC architecture) for Mojolicious applications. Each\nmodel has an `app` attribute.\n\n# OPTIONS\n\n[Mojolicious::Plugin::Model](https://metacpan.org/pod/Mojolicious%3A%3APlugin%3A%3AModel) supports the following options.\n\n## namespaces\n\n    # Mojolicious::Lite\n    plugin Model =\u003e {namespaces =\u003e ['MyApp::Model']};\n\nNamespace to load models from, defaults to `$moniker::Model`.\n\n## base\\_classes\n\n    # Mojolicious::Lite\n    plugin Model =\u003e {base_classes =\u003e ['MyApp::Model']};\n\nBase classes used to identify models, defaults to [MojoX::Model](https://metacpan.org/pod/MojoX%3A%3AModel).\n\n## default\n\n    # Mojolicious::Lite\n    plugin Model =\u003e {default =\u003e 'MyModel'};\n\n    any '/' =\u003e sub {\n      my $c = shift();\n      $c-\u003emodel-\u003edo(); # used model MyModel\n      # ...\n    }\n\nThe name of the default model to use if the name of the current model not\nspecified.\n\n## params\n\n    # Mojolicious::Lite\n    plugin Model =\u003e {params =\u003e {DBI =\u003e {dsn =\u003e 'dbi:mysql:mydb'}}};\n\nParameters to be passed to the class constructor of the model.\n\n# HELPERS\n\n[Mojolicious::Plugin::Model](https://metacpan.org/pod/Mojolicious%3A%3APlugin%3A%3AModel) implements the following helpers.\n\n## model\n\n    my $model = $c-\u003emodel($name);\n\nLoad, create and cache a model object with given name. Default class for\nmodel `camelize($moniker)::Model`. Return `undef` if model not found.\n\n## entity\n\n    my $disposable_model = $c-\u003eentity($name);\n\nCreate a new model object with given name. Default class for\nmodel `camelize($moniker)::Model`. Return `undef` if model not found.\nUse `entity` instead of `model` when you need stateful objects.\n\n# METHODS\n\n[Mojolicious::Plugin::Model](https://metacpan.org/pod/Mojolicious%3A%3APlugin%3A%3AModel) inherits all methods from\n[Mojolicious::Plugin](https://metacpan.org/pod/Mojolicious%3A%3APlugin) and implements the following new ones.\n\n## register\n\n    $plugin-\u003eregister(Mojolicious-\u003enew);\n\nRegister plugin in [Mojolicious](https://metacpan.org/pod/Mojolicious) application.\n\n# SEE ALSO\n\n[Mojolicious](https://metacpan.org/pod/Mojolicious), [Mojolicious::Guides](https://metacpan.org/pod/Mojolicious%3A%3AGuides), [http://mojolicio.us](http://mojolicio.us).\n\n# AUTHOR\n\nAndrey Khozov, `avkhozov@googlemail.com`.\n\n# CONTRIBUTORS\n\nAlexey Stavrov, `logioniz@ya.ru`.\n\nDenis Ibaev, `dionys@gmail.com`.\n\nEugen Konkov, `kes-kes@yandex.ru`.\n\n# COPYRIGHT AND LICENSE\n\nCopyright (C) 2017, Andrey Khozov.\n\nThis program is free software, you can redistribute it and/or modify it under\nthe terms of the Artistic License version 2.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favkhozov%2Fmojolicious-plugin-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favkhozov%2Fmojolicious-plugin-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favkhozov%2Fmojolicious-plugin-model/lists"}