| 1 | package Bookshop; | ||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Punk; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Punk::Plugin::MCP; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Bookshop::Controller::Books; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | cache mcp => { backend => 'file', dir => $ENV{BOOKSHOP_SESSIONS} // '/tmp/bookshop-mcp' }; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{"BOOKSHOP_SESSIONS"} // "/tmp/bookshop-mcp"
MC/DC0%0/1
$ENV{"BOOKSHOP_SESSIONS"} // "/tmp/bookshop-mcp"
$ENV{"BOOKSHOP_SESSIONS"}
Truth table50%1/2
A
A= $ENV{"BOOKSHOP_SESSIONS"}
| |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | my $admin = sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||
| 11 | 4 | my ($c) = @_; | |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | return undef if ($c->req->header('X-Admin-Key') // '') eq ($ENV{BOOKSHOP_ADMIN_KEY} // 'change-me'); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
$c->req->header("X-Admin-Key") // ""
$ENV{"BOOKSHOP_ADMIN_KEY"} // "change-me"
MC/DC100%1/1
$c->req->header("X-Admin-Key") // ""
$c->req->header("X-Admin-Key")
MC/DC0%0/1
$ENV{"BOOKSHOP_ADMIN_KEY"} // "change-me"
$ENV{"BOOKSHOP_ADMIN_KEY"}
Truth table100%2/2
A
A= $c->req->header("X-Admin-Key")
Truth table50%1/2
A
A= $ENV{"BOOKSHOP_ADMIN_KEY"}
| |||||||||||||||||||||||||||||||
| 13 | 2 | return [403, ['Content-Type' => 'text/plain'], ['admins only']]; | |||||||||||||||||||||||||||||
| 14 | 1 | }; | |||||||||||||||||||||||||||||
| 15 | 1 | get '/books' => 'Books#search'; | |||||||||||||||||||||||||||||
| 16 | 1 | get '/books/:id' => 'Books#show'; | |||||||||||||||||||||||||||||
| 17 | 1 | my $admin_scope = under '/admin' => $admin; | |||||||||||||||||||||||||||||
| 18 | 1 | $admin_scope->post('/books' => 'Books#add'); | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | 1 | plugin 'MCP' => { | |||||||||||||||||||||||||||||
| 21 | name => 'bookshop', | ||||||||||||||||||||||||||||||
| 22 | title => 'The Bookshop', | ||||||||||||||||||||||||||||||
| 23 | instructions => 'Search the catalogue before recommending. Book ids are numbers.', | ||||||||||||||||||||||||||||||
| 24 | session => 'mcp', | ||||||||||||||||||||||||||||||
| 25 | logging => 1, | ||||||||||||||||||||||||||||||
| 26 | }; | ||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | 1 | mcp tool => search_books => { | |||||||||||||||||||||||||||||
| 29 | title => 'Search books', | ||||||||||||||||||||||||||||||
| 30 | description => 'Find books whose title or author contains the words given.', | ||||||||||||||||||||||||||||||
| 31 | input => { type => 'object', required => ['q'], | ||||||||||||||||||||||||||||||
| 32 | properties => { q => { type => 'string', description => 'words to look for' } } }, | ||||||||||||||||||||||||||||||
| 33 | output => { type => 'object', required => ['books'], | ||||||||||||||||||||||||||||||
| 34 | properties => { books => { type => 'array' } } }, | ||||||||||||||||||||||||||||||
| 35 | annotations => { readOnlyHint => 1, openWorldHint => 0 }, | ||||||||||||||||||||||||||||||
| 36 | } => 'Books#search'; | ||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | 1 | mcp tool => add_book => { | |||||||||||||||||||||||||||||
| 39 | description => 'Add a book to the catalogue.', | ||||||||||||||||||||||||||||||
| 40 | input => { type => 'object', required => ['title', 'author'], | ||||||||||||||||||||||||||||||
| 41 | properties => { title => { type => 'string' }, | ||||||||||||||||||||||||||||||
| 42 | author => { type => 'string' }, | ||||||||||||||||||||||||||||||
| 43 | year => { type => 'integer' } } }, | ||||||||||||||||||||||||||||||
| 44 | annotations => { destructiveHint => 0, idempotentHint => 0 }, | ||||||||||||||||||||||||||||||
| 45 | guard => $admin, | ||||||||||||||||||||||||||||||
| 46 | } => 'Books#add'; | ||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||
| 48 | 1 | mcp resource => 'books://catalog' => { name => 'catalog', mime => 'application/json', | |||||||||||||||||||||||||||||
| 49 | description => 'Every book, one line each.' } => 'Books#catalog'; | ||||||||||||||||||||||||||||||
| 50 | 1 | mcp resource => 'books://{id}' => { name => 'book', description => 'One book by id.' } => 'Books#show'; | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | 1 | mcp prompt => recommend => { | |||||||||||||||||||||||||||||
| 53 | description => 'Ask for one recommendation from the catalogue.', | ||||||||||||||||||||||||||||||
| 54 | arguments => [{ name => 'mood', description => 'what the reader is in the mood for', required => 1 }], | ||||||||||||||||||||||||||||||
| 55 | } => 'Books#recommend'; | ||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||
| 57 | 1 | 1; | |||||||||||||||||||||||||||||