WordBrain/Word.pm

filter: Statementstmt 100% 25 / 25 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 100% 34 / 34 CC 2 SCAR 2.2
CC
2
Cov
100%
word
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« WordBrain/Letter.pm ↑ Summary WordBrain/Solution.pm »
1 package Game::WordBrain::Word;
2  
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 13 ▶use overload '""' => \&_operator_stringify;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 ▶use Game::WordBrain::Letter;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 13 our $VERSION = '0.2.2'; # VERSION
11 # ABSTRACT: Representation of a Word for WordBrain
12  
13 =head1 NAME
14  
15 Game::WordBrain::Word - Representation of a Word for WordBrain
16  
17 =head1 SYNOPSIS
18  
19 # Create a new word
20 my @letters = (
21 Game::WordBrain::Letter->new( ... ),
22 Game::WordBrain::Letter->new( ... ),
23 ...;
24 );
25  
26 my $word = Game::WordBrain::Word->new( letters => \@letters );
27  
28 # Stringify
29 print $word; # Overloaded Stringification
30 print $word->word; # Explict stringification
31  
32 =head1 DESCRIPTION
33  
34 A L<Game::WordBrain::Word> is composed of an ArrayRef of L<Game::WordBrain::Letter>s that are used to construct it.
35  
36 =head1 ATTRIBUTES
37  
38 =head2 B<letters>
39  
40 An ArrayRefof L<Game::WordBrain::Letter>s that comprise the word.
41  
42 =head1 METHODS
43  
44 =head2 new
45  
46 my @letters = (
47 Game::WordBrain::Letter->new( ... ),
48 Game::WordBrain::Letter->new( ... ),
49 ...;
50 );
51  
52 my $word = Game::WordBrain::Word->new( letters => \@letters );
53  
54 Given an ArrayRef of L<Game::WordBrain::Letter>s, create a new potential WordBrain word.
55  
56 =cut
57  
58 7520 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
59 7520 my $class = shift;
60 7520 my $args = shift;
61  
62 7520 return bless $args, $class;
63 }
64  
65 =head2 word
66  
67 my $word = Game::WordBrain::Word->new( ... );
68  
69 print $word->word;
70  
71 Explict stringification of the word. There is also overloaded " stringification but you are free to use which ever method you are most comfortable with.
72  
73 =cut
74  
75 15789 ▶sub word {
Subroutine word: called CC=2 SCAR=6.9
Pod documented
76 15789 my $self = shift;
77  
78 15789 my $word;
79 15789 for my $letter (@{ $self->{letters} }) {
80 52265 $word .= $letter->{letter};
81 }
82  
83 15789 return $word;
84 }
85  
86 7956 ▶sub _operator_stringify {
Subroutine _operator_stringify: called CC=1 SCAR=0.0
87 7956 my $word = shift;
88  
89 7956 return $word->word;
90 }
91  
92 13 1;
« WordBrain/Letter.pm ↑ Summary WordBrain/Solution.pm »