blib/lib/Games/RolePlay/MapGen/Generator.pm

filter: Statementstmt 100% 80 / 80 Branchbran 57.8% 22 / 38 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 12 totaltotal 76.7% 119 / 155 CC 25 SCAR 14.8
CC
25
Cov
84%
go
10.4
add_plugin
6.2
gen_bounding_size
3.1
CRAP 4.4
« blib/lib/Games/RolePlay/MapGen/GeneratorPlugin/FiveSplit.pm ↑ Summary blib/lib/Games/RolePlay/MapGen/GeneratorPlugin/ClearDoors.pm »
1 # vi:tw=0 syntax=perl:
2  
3 package Games::RolePlay::MapGen::Generator;
4  
5 18 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 16 our @ISA;
9  
10 16 1;
11  
12 # new {{{
13 9 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 9 my $class = shift;
15 9 my $this = bless {o => {@_}}, $class;
16  
17 $this->{plugins} = {
18 9 pre => [ ], # after the entire map is built, this executes on the topnode (before treasure and traps are added)
19  
20 trap => [ ],
21 door => [ ],
22 encr => [ ],
23 tres => [ ],
24  
25 post => [ ], # after the entire map is built and treasure traps and doors are added
26 };
27  
28 9 return $this;
29 }
30 # }}}
31 # gen_opts {{{
32 25 ▶sub gen_opts {
Subroutine gen_opts: called CC=3 SCAR=11.0
Pod undocumented
33 25 my $this = shift;
34 25 my $opts = {@_};
35  
36 25 for my $k (keys %{ $this->{o} }) {
37 400 ▶ $opts->{$k} = $this->{o}{$k} if not exists $opts->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{$k} 271 129 400
38 }
39  
40 25 return $opts;
41 }
42 # }}}
43 # go {{{
44 9 ▶sub go {
Subroutine go: called CC=8 SCAR=23.4
Pod undocumented
45 9 my $this = shift;
46 9 my $opts = $this->gen_opts(@_);
47  
48 9 $this->gen_bounding_size( $opts );
49  
50 9 ▶ croak "ERROR: bounding_box is a required option for " . ref($this) . "::go()" unless $opts->{x_size} and $opts->{y_size};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"x_size"} and $opts->{"y_size"} 0 9 9
Condition33%1/3
$opts->{"x_size"} and $opts->{"y_size"}
!ll&&!rl&&r
009
MC/DC0%0/2
$opts->{"x_size"} and $opts->{"y_size"}
$opts->{"x_size"} $opts->{"y_size"}
Truth table33%1/3
A and B
A= $opts->{"x_size"}B= $opts->{"y_size"}
ABresult
0X0
100
111
51 9 ▶ croak "ERROR: num_rooms is a required option for " . ref($this) . "::go()" unless $opts->{num_rooms};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"num_rooms"} 0 9 9
52  
53 9 ▶ $opts->{min_room_size} = "2x2" unless $opts->{min_room_size};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"min_room_size"} 0 9 9
54 9 ▶ $opts->{max_room_size} = "9x9" unless $opts->{max_room_size};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"max_room_size"} 0 9 9
55  
56 9 ▶ croak "ERROR: room sizes are of the form 9x9, 3x10, 2x2, etc" unless $opts->{min_room_size} =~ m/^\d+x\d+$/ and $opts->{max_room_size} =~ m/^\d+x\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"min_room_size"} =~ /^\d+x\d+$/u and $opts->{"max_room_size"} =~ /^\d+x\d+$/u 0 9 9
Condition33%1/3
$opts->{"min_room_size"} =~ /^\d+x\d+$/u and $opts->{"max_room_size"} =~ /^\d+x\d+$/u
!ll&&!rl&&r
009
MC/DC0%0/2
$opts->{"min_room_size"} =~ /^\d+x\d+$/u and $opts->{"max_room_size"} =~ /^\d+x\d+$/u
$opts->{"min_room_size"} =~ /^\d+x\d+$/u $opts->{"max_room_size"} =~ /^\d+x\d+$/u
Truth table33%1/3
A and B
A= $opts->{"min_room_size"} =~ /^\d+x\d+$/uB= $opts->{"max_room_size"} =~ /^\d+x\d+$/u
ABresult
0X0
100
111
57  
58 9 my ($map, $groups) = $this->genmap( $opts );
59  
60 9 my $changed_options = $this->post_genmap( $opts, $map, $groups );
61  
62 9 return ($map, $groups, $changed_options);
63 }
64 # }}}
65 # gen_bounding_size {{{
66 9 ▶sub gen_bounding_size {
Subroutine gen_bounding_size: called CC=3 SCAR=11.2
Pod undocumented
67 9 my $this = shift;
68 9 my $opts = shift;
69  
70 9 ▶ if( $opts->{bounding_box} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"bounding_box"}) 9 0 9
71 9 ▶ die "ERROR: illegal bounding box description '$opts->{bounding_box}'" unless $opts->{bounding_box} =~ m/^(\d+)x(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"bounding_box"} =~ /^(\d+)x(\d+)/u 0 9 9
72 9 $opts->{x_size} = $1;
73 9 $opts->{y_size} = $2;
74 }
75 }
76 # }}}
77 # post_genmap {{{
78 9 ▶sub post_genmap {
Subroutine post_genmap: called CC=3 SCAR=11.0
Pod undocumented
79 9 my $this = shift;
80 9 my ($opts, $map, $groups) = @_;
81  
82 9 $this->pre( $opts, $map, $groups );
83  
84 9 $this->doorgen( $opts, $map, $groups );
85 9 $this->trapgen( $opts, $map, $groups );
86 9 $this->encountergen( $opts, $map, $groups );
87 9 $this->treasuregen( $opts, $map, $groups );
88  
89 9 $this->post( $opts, $map, $groups );
90  
91 9 my $changed_options = {};
92 9 for my $k (keys %$opts) {
93 160 ▶ $changed_options->{$k} = $opts->{$k} if $opts->{$k} ne $this->{o};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{$k} ne $this->{"o"} 160 0 160
94 }
95  
96 9 return $changed_options;
97 }
98 # }}}
99  
100 # Meant to be overloaded elsewhere:
101 9 ▶sub trapgen { my $this = shift; $_->trapgen(@_) while $_ = shift @{$this->{plugins}{trap}} }
Subroutine trapgen: called CC=2 SCAR=7.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_ = shift @{$$this{"plugins"}{"trap"};} and do { $_->trapgen(@_) } 0 9 9
102 9 ▶sub doorgen { my $this = shift; $_->doorgen(@_) while $_ = shift @{$this->{plugins}{door}} }
Subroutine doorgen: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_ = shift @{$$this{"plugins"}{"door"};} and do { $_->doorgen(@_) } 5 9 14
103 9 ▶sub encountergen { my $this = shift; $_->encountergen(@_) while $_ = shift @{$this->{plugins}{encr}} }
Subroutine encountergen: called CC=2 SCAR=7.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_ = shift @{$$this{"plugins"}{"encr"};} and do { $_->encountergen(@_) } 0 9 9
104 9 ▶sub treasuregen { my $this = shift; $_->treasuregen(@_) while $_ = shift @{$this->{plugins}{tres}} }
Subroutine treasuregen: called CC=2 SCAR=7.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_ = shift @{$$this{"plugins"}{"tres"};} and do { $_->treasuregen(@_) } 0 9 9
105 9 ▶sub post { my $this = shift; $_->post(@_) while $_ = shift @{$this->{plugins}{post}} }
Subroutine post: called CC=2 SCAR=7.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_ = shift @{$$this{"plugins"}{"post"};} and do { $_->post(@_) } 0 9 9
106 9 ▶sub pre { my $this = shift; $_->pre(@_) while $_ = shift @{$this->{plugins}{pre} } }
Subroutine pre: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_ = shift @{$$this{"plugins"}{"pre"};} and do { $_->pre(@_) } 2 9 11
107  
108 # add_plugin {{{
109 7 ▶sub add_plugin {
Subroutine add_plugin: called CC=6 SCAR=18.2
Pod undocumented
110 7 my $this = shift;
111 7 my $plugin = shift;
112  
113 ## This is a nice idea, but it actually sux0rs ... toast
114 ## # Check to see if it works
115 ## push @ISA, $plugin;
116 ## $Games::RolePlay::MapGen::Generator::doorgen =
117  
118 5 ▶ eval "use $plugin";
Subroutine BEGIN: called CC=1 SCAR=0.0
119 7 ▶ croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 7 7
120  
121 7 my $obj;
122 7 eval "\$obj = new $plugin";
123 7 ▶ croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 7 7
124  
125 7 ▶ croak "uesless plugin" unless int(@$obj) > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless int @$obj > 0 0 7 7
126 7 for my $e (@$obj) {
127 7 my $pt = $this->{plugins}{$e};
128 7 ▶ croak "plugin hooks unknown event" unless ref($pt) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pt eq "ARRAY" 0 7 7
129 7 push @$pt, $obj;
130 }
131 }
132 # }}}
« blib/lib/Games/RolePlay/MapGen/GeneratorPlugin/FiveSplit.pm ↑ Summary blib/lib/Games/RolePlay/MapGen/GeneratorPlugin/ClearDoors.pm »