File Coverage

blib/lib/rig/parser/yaml.pm
Criterion Covered Total %
statement 29 34 85.2
branch 10 16 62.5
condition 5 6 83.3
subroutine 7 10 70.0
pod 3 3 100.0
total 54 69 78.2


line stmt bran cond sub pod time code
1             package rig::parser::yaml;
2             BEGIN {
3 6     6   123 $rig::parser::yaml::VERSION = '0.01_04';
4             }
5 6     6   19 use strict;
  6         6  
  6         87  
6 6     6   15 use Carp;
  6         5  
  6         2309  
7              
8             our %rig_files;
9             our $CURR_RC_FILE;
10              
11             sub parse {
12 9     9 1 17 my $self = shift;
13 9   100     25 my $path = $CURR_RC_FILE = shift || $self->_find_first_rig_file();
14 9 100       25 $rig_files{$path} && return $rig_files{$path}; # cache?
15 6 100       20 return undef unless $path;
16             #confess 'No .perlrig file found' unless $path;
17 4         5 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 5 my $self = shift;
26 4         3 my $file = shift;
27 4 50       121 open my $ff, '<', $file or confess $!;
28 4 50       677 my $yaml = YAML::XS::Load( join '',<$ff> ) or confess $@;
29 4         42 close $ff;
30 4         27 return $yaml;
31             }
32              
33             sub _rigpath {
34 2     2   2 my $class = shift;
35             return split( /[\:|\;]/, $ENV{PERL_RIG_PATH})
36 2 50       4 if defined $ENV{PERL_RIG_PATH};
37              
38 2         7 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 4     4   4 my $self = shift;
56 4 100 66     56 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         7 my $home = File::HomeDir->my_home;
61 2         48 for( $self->_rigpath() ) {
62 4         52 my $path = File::Spec->catfile( $_, '.perlrig' );
63 4 50       84 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.01_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