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 10     10   2213 use strict;
  10         11  
  10         218  
4 10     10   27 use warnings;
  10         12  
  10         248  
5              
6 10     10   34 use overload '""' => \&_operator_stringify;
  10         10  
  10         44  
7              
8 10     10   459 use Game::WordBrain::Letter;
  10         13  
  10         1060  
9              
10             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 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 7520     7520 1 5919 my $class = shift;
60 7520         4542 my $args = shift;
61              
62 7520         12414 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 15789     15789 1 13058 my $self = shift;
77              
78 15789         8552 my $word;
79 15789         9935 for my $letter (@{ $self->{letters} }) {
  15789         19932  
80 52265         41604 $word .= $letter->{letter};
81             }
82              
83 15789         47559 return $word;
84             }
85              
86             sub _operator_stringify {
87 7956     7956   46881 my $word = shift;
88              
89 7956         7834 return $word->word;
90             }
91              
92             1;