File Coverage

inc/My/ConfigH.pm
Criterion Covered Total %
statement 12 31 38.7
branch 0 4 0.0
condition 0 2 0.0
subroutine 4 7 57.1
pod 0 3 0.0
total 16 47 34.0


line stmt bran cond sub pod time code
1             package My::ConfigH;
2              
3 2     2   8 use strict;
  2         18  
  2         54  
4 2     2   6 use warnings;
  2         2  
  2         70  
5 2     2   8 use Carp qw( croak );
  2         2  
  2         120  
6 2     2   10 use File::Basename qw( basename );
  2         3  
  2         877  
7              
8             sub new
9             {
10 0     0 0   my($class, $filename) = @_;
11              
12 0   0       $filename ||= "include/ffi_platypus_config.h";
13              
14 0           my $self = bless {
15             content => '',
16             filename => $filename,
17             }, $class;
18              
19 0           $self;
20             }
21              
22             sub define_var
23             {
24 0     0 0   my($self, $key, $value) = @_;
25 0 0         croak "value for $key is not defined" unless defined $value;
26 0           $self->{content} .= "#define $key $value\n";
27             }
28              
29             sub write_config_h
30             {
31 0     0 0   my($self) = @_;
32              
33 0           my $once = uc basename($self->{filename});
34 0           $once =~ s/\./_/g;
35              
36 0           my $fh;
37 0           my $fn = $self->{filename};
38 0 0         open $fh, '>', $fn or die "unable to write to $fn $!";
39 0           print $fh "#ifndef $once\n";
40 0           print $fh "#define $once\n\n";
41 0           print $fh "@{[ $self->{content} ]}\n";
  0            
42 0           print $fh "#endif\n";
43 0           close $fh;
44             }
45              
46             1;