« examples/contacts/untyped/lib/Contacts/Untyped/App.pm
↑ Summary
examples/contacts/typed/lib/Contacts/Typed/View/HTML/Badge.pm »
| 1 | package Contacts::Typed::App; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 3 | ▶ | use File::Basename qw(dirname); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 3 | ▶ | use File::Spec; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | ▶ | use Template::EmbeddedPerl; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 3 | ▶ | use Contacts::Typed::View::HTML::ContactList; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | ▶ | use Contacts::Typed::View::HTML::Badge; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 3 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 13 | 3 | my ($class, %args) = @_; | |||||||||||||||||||
| 14 | 3 | ▶ | my $root = $args{root} || File::Spec->rel2abs( | ||||||||||||||||||
|
Condition33%1/3
$args{'root'} || 'File::Spec'->rel2abs('File::Spec'->catdir(dirname(__FILE__), ('..', '..', '..')))
MC/DC0%0/2
$args{'root'} || 'File::Spec'->rel2abs('File::Spec'->catdir(dirname(__FILE__), ('..', '..', '..')))
$args{'root'}
'File::Spec'->rel2abs('File::Spec'->catdir(dirname(__FILE__), ('..', '..', '..')))
Truth table33%1/3
A || B
A= $args{'root'}B= 'File::Spec'->rel2abs('File::Spec'->catdir(dirname(__FILE__), ('..', '..', '..')))
| |||||||||||||||||||||
| 15 | File::Spec->catdir(dirname(__FILE__), qw(.. .. ..)), | ||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 3 | my $self = bless { | |||||||||||||||||||
| 19 | root => $root, | ||||||||||||||||||||
| 20 | factory_calls => [], | ||||||||||||||||||||
| 21 | }, $class; | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | $self->{engine} = Template::EmbeddedPerl->new( | ||||||||||||||||||||
| 24 | directories => [File::Spec->catdir($root, 'templates')], | ||||||||||||||||||||
| 25 | smart_lines => 1, | ||||||||||||||||||||
| 26 | auto_escape => 1, | ||||||||||||||||||||
| 27 | use_cache => 1, | ||||||||||||||||||||
| 28 | view_namespace => 'Contacts::Typed::View', | ||||||||||||||||||||
| 29 | helpers => { | ||||||||||||||||||||
| 30 | 3 | ▶ | display_heading => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 3 | my ($engine, $value) = @_; | |||||||||||||||||||
| 32 | 3 | return uc $value; | |||||||||||||||||||
| 33 | }, | ||||||||||||||||||||
| 34 | }, | ||||||||||||||||||||
| 35 | 9 | ▶ | view_factory => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 9 | my ($class, $values, $context) = @_; | |||||||||||||||||||
| 37 | 9 | my $view = $class->new( | |||||||||||||||||||
| 38 | %$values, | ||||||||||||||||||||
| 39 | root => $context->root_view, | ||||||||||||||||||||
| 40 | parent => $context->view, | ||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||
| 42 | 9 | push @{$self->{factory_calls}}, { | |||||||||||||||||||
| 43 | class => $class, | ||||||||||||||||||||
| 44 | args => {%$values}, | ||||||||||||||||||||
| 45 | context => $context, | ||||||||||||||||||||
| 46 | view => $view, | ||||||||||||||||||||
| 47 | }; | ||||||||||||||||||||
| 48 | 9 | return $view; | |||||||||||||||||||
| 49 | }, | ||||||||||||||||||||
| 50 | 3 | ); | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 3 | return $self; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 3 | ▶ | sub contacts { | ||||||||||||||||||
|
Subroutine
contacts: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 56 | return [ | ||||||||||||||||||||
| 57 | 3 | {name => '<Ada>', email => 'ada@example.test'}, | |||||||||||||||||||
| 58 | {name => 'Grace', email => 'grace@example.test'}, | ||||||||||||||||||||
| 59 | ]; | ||||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 1 | ▶ | sub root_view { $_[0]->{root_view} } | ||||||||||||||||||
|
Subroutine
root_view: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 63 | 3 | ▶ | sub factory_calls { $_[0]->{factory_calls} } | ||||||||||||||||||
|
Subroutine
factory_calls: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 3 | ▶ | sub render { | ||||||||||||||||||
|
Subroutine
render: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 66 | 3 | my ($self) = @_; | |||||||||||||||||||
| 67 | 3 | $self->{factory_calls} = []; | |||||||||||||||||||
| 68 | 3 | my $contacts = $self->contacts; | |||||||||||||||||||
| 69 | 3 | $self->{root_view} = Contacts::Typed::View::HTML::ContactList->new( | |||||||||||||||||||
| 70 | title => 'Contacts', | ||||||||||||||||||||
| 71 | contacts => $contacts, | ||||||||||||||||||||
| 72 | prebuilt_badge => Contacts::Typed::View::HTML::Badge->new( | ||||||||||||||||||||
| 73 | label => scalar(@$contacts) . ' contacts', | ||||||||||||||||||||
| 74 | ), | ||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||
| 76 | 3 | return $self->{engine}->render_view($self->{root_view}); | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 3 | 1; | |||||||||||||||||||