File Coverage

blib/lib/Story/Interact/Page.pm
Criterion Covered Total %
statement 33 41 80.4
branch n/a
condition n/a
subroutine 11 14 78.5
pod 0 3 0.0
total 44 58 75.8


line stmt bran cond sub pod time code
1 5     5   186 use 5.010001;
  5         70  
2 5     5   40 use strict;
  5         18  
  5         135  
3 5     5   47 use warnings;
  5         19  
  5         361  
4              
5             package Story::Interact::Page;
6              
7             our $AUTHORITY = 'cpan:TOBYINK';
8             our $VERSION = '0.001012';
9              
10 5     5   47 use Moo;
  5         303  
  5         111  
11 5     5   1737 use Types::Common -types;
  5         14  
  5         39  
12 5     5   66409 use namespace::clean;
  5         13  
  5         227  
13              
14             use overload (
15 0     0   0 q[bool] => sub { 1 },
16 0     0   0 q[""] => sub { shift->name },
17 5         130 fallback => 1,
18 5     5   4940 );
  5         12  
19              
20             has 'id' => (
21             is => 'ro',
22             isa => Str,
23             required => 1,
24             );
25              
26             has 'location' => (
27             is => 'rwp',
28             isa => Str,
29             predicate => 1,
30             );
31              
32             has 'abstract' => (
33             is => 'rwp',
34             isa => Str,
35             predicate => 1,
36             );
37              
38             has 'todo' => (
39             is => 'rwp',
40             isa => Bool,
41             default => 0,
42             );
43              
44             has 'text' => (
45             is => 'ro',
46             isa => ArrayRef->of( Str ),
47 45     45   1948 builder => sub { [] },
48             );
49              
50             has 'next_pages' => (
51             is => 'ro',
52             isa => ArrayRef->of(
53             Tuple->of(
54             NonEmptyStr,
55             NonEmptyStr,
56             Optional->of( HashRef ),
57             ),
58             ),
59 45     45   19505 builder => sub { [] },
60             );
61              
62             sub add_text {
63 65     65 0 138 my ( $self, $text ) = @_;
64 65         262 my @chunks = split /\n\s*\n/sm, $text;
65 65         651 s/(?:^\s+|\s+$)//g for @chunks;
66 65         499 s/\s+/ /g for @chunks;
67 65         111 push @{ $self->text }, @chunks;
  65         206  
68 65         1393 return;
69             }
70              
71             sub add_next_page {
72 74     74 0 157 my ( $self, $page_id, $desc, %extra ) = @_;
73 74         109 push @{ $self->next_pages }, [ $page_id, $desc, \%extra ];
  74         224  
74 74         1505 return;
75             }
76              
77             sub reset_next_pages {
78 0     0 0   my $self = shift;
79 0           my @r = @{ $self->next_pages };
  0            
80 0           @{ $self->next_pages } = ();
  0            
81 0           return \@r;
82             }
83              
84             1;