File Coverage

blib/lib/rig/parser/yaml.pm
Criterion Covered Total %
statement 28 33 84.8
branch 10 16 62.5
condition 5 6 83.3
subroutine 6 9 66.6
pod 3 3 100.0
total 52 67 77.6


line stmt bran cond sub pod time code
1             package rig::parser::yaml;
2             {
3             $rig::parser::yaml::VERSION = '0.04';
4             }
5 6     6   30 use strict;
  6         11  
  6         235  
6 6     6   31 use Carp;
  6         15  
  6         3695  
7              
8             our %rig_files;
9             our $CURR_RC_FILE;
10              
11             sub parse {
12 10     10 1 16 my $self = shift;
13 10   100     49 my $path = $CURR_RC_FILE = shift || $self->_find_first_rig_file();
14 10 100       376 $rig_files{$path} && return $rig_files{$path}; # cache?
15 6 100       24 return undef unless $path;
16             #confess 'No .perlrig file found' unless $path;
17 4         13 return $rig_files{$path} = $self->parse_file( $path );
18             }
19              
20             sub file {
21 0     0 1 0 return $CURR_RC_FILE;
22             }
23              
24             sub parse_file {
25 4     4 1 6 my $self = shift;
26 4         7 my $file = shift;
27 4 50       177 open my $ff, '<', $file or confess $!;
28 4 50       1341 my $yaml = YAML::XS::Load( join '',<$ff> ) or confess $@;
29 4         68 close $ff;
30 4         31 return $yaml;
31             }
32              
33             sub _rigpath {
34 2     2   4 my $class = shift;
35 2 50       8 return split( /[\:|\;]/, $ENV{PERL_RIG_PATH})
36             if defined $ENV{PERL_RIG_PATH};
37              
38 2         19 return( Cwd::getcwd, File::HomeDir->my_home ); #TODO add caller's home
39             }
40              
41              
42             sub _is_module_task {
43 0     0   0 shift =~ /^\:/;
44             }
45              
46             sub _has_rigfile_tasks {
47 0     0   0 my $self = shift;
48 0         0 for( @_ ) {
49 0 0       0 return 1 unless _is_module_task($_)
50             }
51             }
52              
53              
54             sub _find_first_rig_file {
55 5     5   9 my $self = shift;
56 5 100 66     109 return $ENV{PERLRIG_FILE} if defined $ENV{PERLRIG_FILE} && -e $ENV{PERLRIG_FILE};
57 2         2 my $path;
58             # search path
59 2         19 my $current = Cwd::getcwd;
60 2         18 my $home = File::HomeDir->my_home;
61 2         98 for( $self->_rigpath() ) {
62 4         105 my $path = File::Spec->catfile( $_, '.perlrig' );
63 4 50       79 return $path if -e $path;
64             }
65              
66             # not in path, or no path specified
67             }
68             1;
69              
70             =head1 NAME
71              
72             rig::parser::yaml - YAML parser for rig
73              
74             =head1 VERSION
75              
76             version 0.04
77              
78             =head1 DESCRIPTION
79              
80             This is used by the base engine to find and parse .perlrig YAML files.
81              
82             =head1 METHODS
83              
84             =head2 parse
85              
86             Main method, called by C to parse a file.
87              
88             =head2 file
89              
90             Returns the current loaded file.
91              
92             =head2 parse_file
93              
94             Loads a YAML file using L.
95              
96             =cut