| 1 | package Bookshop::Controller::Books; | ||||||||||||||||||||
| 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 | |||||||||||||||||||||
| 5 | 1 | my %BOOKS = ( | |||||||||||||||||||
| 6 | 1 => { id => 1, title => 'Dune', author => 'Frank Herbert', year => 1965 }, | ||||||||||||||||||||
| 7 | 2 => { id => 2, title => 'The Dispossessed', author => 'Ursula K. Le Guin', year => 1974 }, | ||||||||||||||||||||
| 8 | 3 => { id => 3, title => 'Hyperion', author => 'Dan Simmons', year => 1989 }, | ||||||||||||||||||||
| 9 | ); | ||||||||||||||||||||
| 10 | 1 | my $NEXT = 4; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | ▶ | sub search { | ||||||||||||||||||
|
Subroutine
search: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 13 | 2 | my ($c) = @_; | |||||||||||||||||||
| 14 | 2 | ▶ | my $q = lc($c->param('q') // ''); | ||||||||||||||||||
|
Condition50%1/2
$c->param("q") // ""
MC/DC0%0/1
$c->param("q") // ""
$c->param("q")
Truth table50%1/2
A
A= $c->param("q")
| |||||||||||||||||||||
| 15 | 6 | my @hits = grep { index(lc "$_->{title} $_->{author}", $q) >= 0 } | |||||||||||||||||||
| 16 | 2 | map { $BOOKS{$_} } sort { $a <=> $b } keys %BOOKS; | |||||||||||||||||||
| 17 | 2 | $c->mcp_log('info', { searched => $q, found => scalar @hits }); | |||||||||||||||||||
| 18 | 2 | return { books => \@hits }; | |||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 2 | ▶ | sub show { | ||||||||||||||||||
|
Subroutine
show: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||
| 22 | 2 | my ($c) = @_; | |||||||||||||||||||
| 23 | 2 | ▶ | my $book = $BOOKS{ $c->param('id') // '' } or return [404, ['Content-Type' => 'text/plain'], ['no such book']]; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$c->param("id") // ""
MC/DC0%0/1
$c->param("id") // ""
$c->param("id")
Truth table50%1/2
A
A= $c->param("id")
| |||||||||||||||||||||
| 24 | 1 | return $c->json($book); | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 1 | ▶ | sub catalog { | ||||||||||||||||||
|
Subroutine
catalog: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 28 | 1 | my ($c) = @_; | |||||||||||||||||||
| 29 | 1 | return [ map { "$_->{id}: $_->{title}" } map { $BOOKS{$_} } sort { $a <=> $b } keys %BOOKS ]; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 1 | ▶ | sub add { | ||||||||||||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 33 | 1 | my ($c) = @_; | |||||||||||||||||||
| 34 | 1 | my $id = $NEXT++; | |||||||||||||||||||
| 35 | 1 | $BOOKS{$id} = { id => $id, title => $c->param('title'), author => $c->param('author'), | |||||||||||||||||||
| 36 | year => $c->param('year') }; | ||||||||||||||||||||
| 37 | 1 | $c->mcp_resource_updated('books://catalog'); | |||||||||||||||||||
| 38 | 1 | return $c->json($BOOKS{$id}); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 1 | ▶ | sub recommend { | ||||||||||||||||||
|
Subroutine
recommend: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 42 | 1 | my ($c) = @_; | |||||||||||||||||||
| 43 | 1 | my $mood = $c->param('mood'); | |||||||||||||||||||
| 44 | return [ | ||||||||||||||||||||
| 45 | 1 | { role => 'user', content => "Recommend one book from books://catalog for someone who wants $mood. Say why in two sentences." }, | |||||||||||||||||||
| 46 | ]; | ||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 1 | 1; | |||||||||||||||||||