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         27  
2 5     5   29 use strict;
  5         21  
  5         108  
3 5     5   35 use warnings;
  5         16  
  5         397  
4              
5             package Story::Interact::PageSource;
6              
7             our $AUTHORITY = 'cpan:TOBYINK';
8             our $VERSION = '0.001012';
9              
10 5     5   55 use Story::Interact::Page ();
  5         19  
  5         147  
11 5     5   2282 use Story::Interact::Syntax ();
  5         14  
  5         128  
12              
13 5     5   50 use Moo::Role;
  5         14  
  5         66  
14 5     5   2752 use Types::Common -types;
  5         13  
  5         37  
15 5     5   71609 use Carp qw( croak );
  5         13  
  5         280  
16 5     5   2999 use Safe ();
  5         85640  
  5         194  
17 5     5   53 use namespace::clean;
  5         11  
  5         56  
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   173 builder => sub { shift->get_source_code( '_prelude' ) // '' },
26             );
27              
28             sub get_page {
29 45     45 0 115 my ( $self, $state, $page_id ) = @_;
30 45         205 my $code = $self->get_source_code( $page_id );
31              
32 45 50       8482 return Story::Interact::Page->new( id => ':end' ) unless $code;
33              
34 45 100       1182 if ( my $prelude = $self->prelude_code ) {
35 1         315 $code = sprintf( "%s;\n%s", $prelude, $code );
36             }
37              
38 45         969 Story::Interact::Syntax::START( $state, $page_id );
39 45 50   5 0 5641 eval( "package Story::Interact::Syntax; use strict; use warnings; no warnings qw( numeric uninitialized ); $code; 1" )
  5     4   64  
  5     4   31  
  4     4   94  
  4     3   27  
  4     3   26  
  4     3   138  
  4     3   22  
  4     3   22  
  4     3   379  
  4     3   46  
  4     3   17  
  4     2   102  
  3     2   67  
  3     2   6  
  3     2   122  
  3     2   17  
  3     2   22  
  3     2   224  
  3     2   26  
  3     2   6  
  3     2   117  
  3     2   18  
  3     2   8  
  3     2   125  
  3     2   18  
  3     2   7  
  3     2   262  
  3     2   27  
  3     2   7  
  3     2   93  
  3     2   27  
  3     2   6  
  3     2   140  
  3     2   20  
  3     2   6  
  3     2   268  
  2     2   14  
  2     2   5  
  2     2   76  
  2     2   12  
  2     2   5  
  2     2   65  
  2     2   11  
  2     2   5  
  2     2   208  
  2     2   13  
  2     2   5  
  2     1   45  
  2     1   11  
  2     1   4  
  2     1   74  
  2     1   22  
  2     1   4  
  2     1   169  
  2     1   16  
  2     1   5  
  2     1   54  
  2     1   10  
  2     1   5  
  2     1   68  
  2     1   12  
  2     1   6  
  2     1   198  
  2     1   14  
  2     1   7  
  2     1   81  
  2     1   13  
  2     1   6  
  2     1   95  
  2     1   12  
  2     1   4  
  2         191  
  2         15  
  2         5  
  2         51  
  2         10  
  2         9  
  2         64  
  2         9  
  2         10  
  2         109  
  2         13  
  2         5  
  2         58  
  2         13  
  2         3  
  2         60  
  2         11  
  2         3  
  2         113  
  2         15  
  2         5  
  2         66  
  2         15  
  2         7  
  2         63  
  2         12  
  2         4  
  2         187  
  2         14  
  2         11  
  2         63  
  2         12  
  2         7  
  2         91  
  2         18  
  2         5  
  2         200  
  2         18  
  2         6  
  2         45  
  2         11  
  2         4  
  2         112  
  2         14  
  2         5  
  2         175  
  2         14  
  2         16  
  2         48  
  2         9  
  2         4  
  2         60  
  2         13  
  2         9  
  2         152  
  2         14  
  2         19  
  2         45  
  2         10  
  2         7  
  2         91  
  2         18  
  2         4  
  2         214  
  2         20  
  2         5  
  2         65  
  2         12  
  2         4  
  2         74  
  2         12  
  2         5  
  2         182  
  1         25  
  1         2  
  1         23  
  1         6  
  1         2  
  1         28  
  1         5  
  1         4  
  1         92  
  1         8  
  1         3  
  1         27  
  1         5  
  1         2  
  1         29  
  1         30  
  1         2  
  1         74  
  1         9  
  1         10  
  1         24  
  1         4  
  1         2  
  1         42  
  1         7  
  1         3  
  1         88  
  1         7  
  1         12  
  1         38  
  1         8  
  1         10  
  1         49  
  1         7  
  1         2  
  1         106  
  1         9  
  1         2  
  1         30  
  1         12  
  1         2  
  1         29  
  1         5  
  1         3  
  1         47  
  1         21  
  1         6  
  1         51  
  1         6  
  1         3  
  1         39  
  1         11  
  1         4  
  1         79  
  1         8  
  1         4  
  1         25  
  1         10  
  1         3  
  1         30  
  1         6  
  1         11  
  1         97  
  1         7  
  1         6  
  1         25  
  1         5  
  1         11  
  1         30  
  1         6  
  1         3  
  1         118  
40             or croak( "Died on page '$page_id': $@" );
41 45         205 return Story::Interact::Syntax::FINISH( $state );
42             }
43              
44             1;