Boy/App.pm

filter: Statementstmt 88.2% 15 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.3% 21 / 23 CC 1 SCAR 0.5
CC
1
Cov
88%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Boy.pm ↑ Summary
1 package Chandra::Same::Boy::App;
2  
3 1 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Object::Proto::Sugar qw(is_ro is_rw);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 0 ▶use Chandra::App;
Subroutine BEGIN: called CC=1 SCAR=2.6
9 use Chandra::Same::Boy;
10  
11 our $VERSION = '0.02';
12  
13 has rom => (is_ro); # required (checked in BUILD)
14 has title => (is_ro, default => 'Game Boy');
15 has model => (is_ro, default => 'cgb');
16 has scale => (is_rw, default => 3); # coerced to a truthy value in BUILD
17 has width => (is_rw); # defaulted from scale in BUILD
18 has height => (is_rw); # defaulted from scale in BUILD
19 has debug => (is_ro, default => 0);
20 has sample_rate => (is_ro, default => 44100);
21 has on => (is_ro, default => sub { +{} });
22  
23 has app => (is_rw);
24 has widget => (is_rw);
25  
26 sub BUILD {
27 my ($self) = @_;
28 Carp::croak("Chandra::Same::Boy::App: 'rom' is required")
29 unless defined $self->rom;
30  
31 my $scale = $self->scale || 3;
32 $self->scale($scale);
33  
34 my $w = $self->width || (160 * $scale);
35 $w = 380 if $w < 380; # room for the toolbar
36 my $h = $self->height || (144 * $scale + 36); # + toolbar height
37 $self->width($w);
38 $self->height($h);
39 return;
40 }
41  
42 sub run {
43 my ($self) = @_;
44  
45 my $app = Chandra::App->new(
46 title => $self->title,
47 width => $self->width,
48 height => $self->height,
49 debug => $self->debug,
50 );
51 my $gb = Chandra::Same::Boy->new(
52 app => $app,
53 rom => $self->rom,
54 model => $self->model,
55 scale => $self->scale,
56 sample_rate => $self->sample_rate,
57 on => $self->on,
58 );
59  
60 $self->app($app);
61 $self->widget($gb);
62  
63 $gb->mount; # canvas + input + game loop
64 $app->run; # blocks until the window closes
65 $gb->shutdown; # flush cartridge battery on exit
66 return $self;
67 }
68  
69 1;
70  
71 __END__
« Boy.pm ↑ Summary