NAME
Punk::Model::Markdown - a Punk::Model backend over a markdown mount's pages
SYNOPSIS
# the app
markdown '/blog' => 'posts', sort => 'date';
database blog => { backend => 'Punk::Model::Markdown', prefix => '/blog' };
model;
# the model
package MyApp::Model::Post;
use Punk::Model;
database 'blog';
table 'posts';
field path => { type => 'string', primary => 1 };
field url => { type => 'string' };
field title => { type => 'string' };
field date => { type => 'integer' };
field updated => { type => 'integer' };
field summary => { type => 'string' };
field meta => { type => 'object' };
# anywhere
my $latest = $c->model('Post')->search({ date => { '!=' => undef } },
{ order_by => [ date => 'desc' ], limit => 3 })->{rows};
DESCRIPTION
The pages of the markdown mount at prefix, as rows: exactly what "LISTING" in Punk::Mount::Markdown lists (url, path, title, date, updated, summary, meta), read straight from the mount's page table, so a blog's posts are a model like the rest of an application's data. Drafts are not rows, because they are not pages. Under the mount's reload, meta and the dates follow the last re-read of each page.
Searching works as on Punk::Model::JSONFile: the same filters, ordering and tokens as Punk::Model::DBI, evaluated in memory.
The files are the pages, so create, update and delete croak.
Punk::Model hands every backend it builds the application, which is how this one finds the mount; the database needs only the prefix. Asked before the application has compiled, or for a prefix with no markdown mount, it croaks as markdown_pages does.
THE CONTRACT
get(%key)
The page whose key columns equal the values (usually path => '/hello'), copied, or undef.
search(\%filter, \%opts)
A page of pages, { rows, has_more_data, next }, as on Punk::Model::DBI.
count(\%filter)
How many pages match.
all()
search({}, {}).
create
update
delete
Croak: the pages are the markdown files.
METHODS
new
Called by Punk::Model with the database options (which must include a prefix), the table, the primary key, the columns and the application.