File Coverage

blib/lib/Game/WordBrain/Word.pm
Criterion Covered Total %
statement 23 23 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 32 32 100.0


line stmt bran cond sub pod time code
1             package Game::WordBrain::Word;
2              
3 9     9   2465 use strict;
  9         14  
  9         244  
4 9     9   34 use warnings;
  9         13  
  9         287  
5              
6 9     9   38 use overload '""' => \&_operator_stringify;
  9         10  
  9         46  
7              
8 9     9   491 use Game::WordBrain::Letter;
  9         11  
  9         1159  
9              
10             our $VERSION = '0.2.1'; # 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 is composed of an ArrayRef of Ls that are used to construct it.
35              
36             =head1 ATTRIBUTES
37              
38             =head2 B
39              
40             An ArrayRefof Ls 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 Ls, create a new potential WordBrain word.
55              
56             =cut
57              
58             sub new {
59 7     7 1 81 my $class = shift;
60 7         11 my $args = shift;
61              
62 7         19 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             sub word {
76 8     8 1 13 my $self = shift;
77              
78 8         10 my $word;
79 8         8 for my $letter (@{ $self->{letters} }) {
  8         192  
80 52         132 $word .= $letter->{letter};
81             }
82              
83 8         55 return $word;
84             }
85              
86             sub _operator_stringify {
87 7     7   3818 my $word = shift;
88              
89 7         16 return $word->word;
90             }
91              
92             1;