Christian Walde

NAME

Dancer2::Plugin::Model - gantry to hang a model layer onto Dancer2

VERSION

version 1.152120

SYNOPSIS

In your app:

    package My;
    use Dancer2;
    use Dancer2::Plugin::Model;
    
    configure_model db => make_db();
    set_model;
    
    any '/' => sub {
        template 'index', { news => model( "News" )->get_latest };
    };

In the model factory:

    package My::Model;
    
    use Module::Runtime 'use_module';
    use Moo;
    
    has db => is => ro => required => 1;
    
    sub get {
        my ( $self, $entity_name ) = @_;
        use_module( __PACKAGE__ . "::$entity_name" )->new( db => $self->db );
    }

In the model entity:

    package My::Model;
    
    use Moo;
    
    has db => is => ro => required => 1;
    
    sub get_latest {
        my ( $self ) = @_;
        
        $self->db->search(
            "events",
            where => { event => 'New' }, sort => { date  => -1 }, per_page => 5,
        );
    }

SUPPORT

Bugs / Feature Requests

Please report any bugs or feature requests through the issue tracker at http://rt.cpan.org/Public/Dist/Display.html?Name=Dancer2-Plugin-Model. You will be notified automatically of any progress on your issue.

Source Code

This is open source software. The code repository is available for public review and contribution under the terms of the license.

https://github.com/wchristian/Dancer2-Plugin-Model

  git clone https://github.com/wchristian/Dancer2-Plugin-Model.git

AUTHOR

Christian Walde <walde.christian@gmail.com>

COPYRIGHT AND LICENSE

Christian Walde has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law.

Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author.