Hexgrid/Sprite.pm

filter: Statementstmt 21.7% 10 / 46 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 18.7% 3 / 16 Podpod 100% 12 / 12 totaltotal 31.2% 25 / 80 CC 4 SCAR 17.3
CC
4
Cov
19%
new
20.0
new_scaled
2.0
copy
2.0
CRAP 5.6
« example.pl ↑ Summary Hexgrid/Tile.pm »
1 package Gtk2::Hexgrid::Sprite;
2 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 0 ▶sub new{
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
7 0 my $class = shift;
8 0 my $type = shift;
9
10 0 my $self= {
11 tile => undef,
12 type => $type,
13 priority => 0
14 };
15 0 ▶ if ($type eq 'text'){
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'text') { } 0 0 0
elsif ($type eq 'image') { } 0 0 0
16 0 $self->{text} = shift;
17 0 $self->{size} = shift; #font size, such as 18
18 }
19 elsif($type eq 'image'){
20 0 my $name = shift;
21 0 ▶ croak 'image needs name' unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
22 0 $self->{imageName} = $name;
23 }
24 0 bless $self, $class;
25 0 return $self;
26 }
27  
28 #only for images (no text)
29 0 ▶sub new_scaled{
Subroutine new_scaled: not called CC=1 SCAR=6.9
Pod documented
30 0 my ($class, $hexgrid, $filename) = @_;
31 0 my $imagename = $filename;
32 0 $imagename .= "~scaled";
33 0 $hexgrid->load_image ($imagename, $filename, 1);
34 0 my $self = new ($class, 'image', $imagename);
35 0 $self->set_priority(0);
36 0 return $self;
37 }
38  
39 0 ▶sub copy{
Subroutine copy: not called CC=1 SCAR=6.9
Pod documented
40 0 my $self = shift;
41 0 my %copy = %$self;
42 0 return \%copy;
43 }
44 #attach to tile
45 0 ▶sub attach{
Subroutine attach: not called CC=1 SCAR=6.9
Pod documented
46 0 my ($self, $tile) = @_;
47 0 $tile->add_sprite($self);
48 }
49 #detach from tile
50 0 ▶sub detach{
Subroutine detach: not called CC=1 SCAR=6.9
Pod documented
51 0 my $self = shift;
52 0 my $tile = $self->tile;
53 0 $tile->remove_sprite($self);
54 }
55 0 ▶sub set_priority{ #place in the drawing order
Subroutine set_priority: not called CC=1 SCAR=6.9
Pod documented
56 0 my ($self, $p) = @_;
57 0 $self->{priority} = $p;
58 }
59 0 ▶sub _set_tile{ #the tile that it it attached to
Subroutine _set_tile: not called CC=1 SCAR=6.9
60 0 my ($self, $tile) = @_;
61 0 $self->{tile} = $tile;
62 }
63  
64 0 ▶sub imageName{
Subroutine imageName: not called CC=1 SCAR=6.9
Pod documented
65 shift->{imageName}
66 0 }
67  
68 0 ▶sub tile{
Subroutine tile: not called CC=1 SCAR=6.9
Pod documented
69 shift->{tile}
70 0 }
71 0 ▶sub type{
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
72 shift->{type}
73 0 }
74 0 ▶sub text{
Subroutine text: not called CC=1 SCAR=6.9
Pod documented
75 shift->{text}
76 0 }
77 0 ▶sub size{
Subroutine size: not called CC=1 SCAR=6.9
Pod documented
78 shift->{size}
79 0 }
80 0 ▶sub priority{
Subroutine priority: not called CC=1 SCAR=6.9
Pod documented
81 shift->{priority}
82 0 }
83 1 q ! positively!
84 __END__
« example.pl ↑ Summary Hexgrid/Tile.pm »