File Coverage

blib/lib/Papery/Analyzer.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Papery::Analyzer;
2              
3 1     1   6 use strict;
  1         2  
  1         56  
4 1     1   6 use warnings;
  1         2  
  1         54  
5              
6 1     1   7 use File::Spec;
  1         5  
  1         39  
7 1     1   726 use YAML::Tiny qw( Load );
  0            
  0            
8              
9             sub analyze_file {
10             my ( $class, $pulp, $path ) = @_;
11             my $meta = $pulp->{meta};
12              
13             # $file is relative to __source
14             my $abspath = File::Spec->catfile( $meta->{__source}, $path );
15              
16             open my $fh, $abspath or die "Can't open $path: $!";
17             local $/;
18             my $source = <$fh>;
19             close $fh;
20              
21             # compute file extension
22             my $ext = ( split /\./, $path )[-1];
23             $meta->{_processor} = $meta->{_processors}{$ext}
24             if exists $meta->{_processors}{$ext};
25              
26             # update meta
27             $meta->{__source_path} = $path;
28             $meta->{__source_abspath} = $abspath;
29             $meta->{_source} = $source;
30             return $class->analyze($pulp);
31             }
32              
33             sub analyze {
34             my ( $class, $pulp ) = @_;
35             my $text = $pulp->{meta}{_source};
36              
37             # take the metadata out
38             if ( $text =~ /\A---\n/ ) {
39             ( undef, my $meta, $text ) = split /^---\n/m, $text, 3;
40             $pulp->merge_meta( Load($meta) );
41             }
42              
43             $pulp->{meta}{_text} = $text;
44             return $pulp;
45             }
46              
47             1;
48              
49             __END__