File Coverage

blib/lib/Story/Interact/PageSource.pm
Criterion Covered Total %
statement 254 254 100.0
branch 4 6 66.6
condition 2 2 100.0
subroutine 84 84 100.0
pod 0 2 0.0
total 344 348 98.8


line stmt bran cond sub pod time code
1 5     5   127 use 5.010001;
  5         20  
2 5     5   78 use strict;
  5         14  
  5         140  
3 5     5   43 use warnings;
  5         18  
  5         358  
4              
5             package Story::Interact::PageSource;
6              
7             our $AUTHORITY = 'cpan:TOBYINK';
8             our $VERSION = '0.001013';
9              
10 5     5   38 use Story::Interact::Page ();
  5         12  
  5         118  
11 5     5   2195 use Story::Interact::Syntax ();
  5         22  
  5         146  
12              
13 5     5   58 use Moo::Role;
  5         13  
  5         70  
14 5     5   2925 use Types::Common -types;
  5         13  
  5         42  
15 5     5   75100 use Carp qw( croak );
  5         19  
  5         288  
16 5     5   2982 use Safe ();
  5         85670  
  5         198  
17 5     5   41 use namespace::clean;
  5         23  
  5         68  
18              
19             requires 'get_source_code';
20             requires 'all_page_ids';
21              
22             has prelude_code => (
23             is => 'lazy',
24             isa => Str,
25 8   100 8   145 builder => sub { shift->get_source_code( '_prelude' ) // '' },
26             );
27              
28             sub get_page {
29 45     45 0 119 my ( $self, $state, $page_id ) = @_;
30 45         142 my $code = $self->get_source_code( $page_id );
31              
32 45 50       7712 return Story::Interact::Page->new( id => ':end' ) unless $code;
33              
34 45 100       1154 if ( my $prelude = $self->prelude_code ) {
35 1         250 $code = sprintf( "%s;\n%s", $prelude, $code );
36             }
37              
38 45         892 Story::Interact::Syntax::START( $state, $page_id );
39 45 50   5 0 5471 eval( "package Story::Interact::Syntax; use strict; use warnings; no warnings qw( numeric uninitialized ); $code; 1" )
  5     4   48  
  5     4   32  
  4     4   96  
  4     3   22  
  4     3   8  
  4     3   121  
  4     3   65  
  4     3   10  
  4     3   325  
  4     3   29  
  4     3   12  
  4     2   84  
  3     2   15  
  3     2   15  
  3     2   130  
  3     2   18  
  3     2   7  
  3     2   215  
  3     2   26  
  3     2   6  
  3     2   98  
  3     2   20  
  3     2   6  
  3     2   131  
  3     2   27  
  3     2   10  
  3     2   233  
  3     2   23  
  3     2   7  
  3     2   83  
  3     2   16  
  3     2   7  
  3     2   110  
  3     2   20  
  3     2   35  
  3     2   265  
  2     2   16  
  2     2   14  
  2     2   46  
  2     2   11  
  2     2   5  
  2     2   58  
  2     2   11  
  2     2   4  
  2     2   138  
  2     2   14  
  2     2   5  
  2     1   49  
  2     1   26  
  2     1   5  
  2     1   70  
  2     1   12  
  2     1   4  
  2     1   131  
  2     1   14  
  2     1   5  
  2     1   58  
  2     1   12  
  2     1   4  
  2     1   61  
  2     1   11  
  2     1   4  
  2     1   158  
  2     1   14  
  2     1   7  
  2     1   58  
  2     1   12  
  2     1   4  
  2     1   64  
  2     1   12  
  2     1   4  
  2         194  
  2         16  
  2         4  
  2         66  
  2         12  
  2         5  
  2         93  
  2         13  
  2         5  
  2         138  
  2         17  
  2         4  
  2         49  
  2         11  
  2         4  
  2         69  
  2         12  
  2         5  
  2         138  
  2         17  
  2         5  
  2         60  
  2         11  
  2         4  
  2         85  
  2         13  
  2         7  
  2         184  
  2         16  
  2         14  
  2         143  
  2         16  
  2         5  
  2         76  
  2         13  
  2         4  
  2         177  
  2         18  
  2         5  
  2         47  
  2         13  
  2         6  
  2         71  
  2         11  
  2         4  
  2         165  
  2         14  
  2         4  
  2         46  
  2         12  
  2         4  
  2         103  
  2         13  
  2         4  
  2         129  
  2         15  
  2         4  
  2         70  
  2         14  
  2         5  
  2         65  
  2         10  
  2         4  
  2         184  
  2         15  
  2         4  
  2         61  
  2         13  
  2         4  
  2         73  
  2         13  
  2         5  
  2         217  
  1         7  
  1         2  
  1         37  
  1         6  
  1         3  
  1         43  
  1         7  
  1         2  
  1         98  
  1         7  
  1         4  
  1         22  
  1         5  
  1         2  
  1         42  
  1         7  
  1         2  
  1         72  
  1         7  
  1         3  
  1         24  
  1         6  
  1         2  
  1         27  
  1         5  
  1         3  
  1         90  
  1         7  
  1         3  
  1         48  
  1         6  
  1         3  
  1         30  
  1         5  
  1         7  
  1         96  
  1         7  
  1         3  
  1         24  
  1         5  
  1         3  
  1         29  
  1         5  
  1         2  
  1         46  
  1         7  
  1         3  
  1         29  
  1         5  
  1         6  
  1         45  
  1         7  
  1         2  
  1         72  
  1         7  
  1         3  
  1         23  
  1         5  
  1         2  
  1         48  
  1         7  
  1         2  
  1         95  
  1         7  
  1         2  
  1         36  
  1         6  
  1         3  
  1         41  
  1         6  
  1         7  
  1         89  
40             or croak( "Died on page '$page_id': $@" );
41 45         201 return Story::Interact::Syntax::FINISH( $state );
42             }
43              
44             1;