File Coverage

blib/lib/Object/HashBase/Inline.pm
Criterion Covered Total %
statement 56 56 100.0
branch 19 26 73.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 81 89 91.0


line stmt bran cond sub pod time code
1             package Object::HashBase::Inline;
2 1     1   339 use strict;
  1         2  
  1         22  
3 1     1   4 use warnings;
  1         1  
  1         34  
4              
5             our $VERSION = '0.008';
6              
7 1     1   23 BEGIN { $Object::HashBase::Test::NO_RUN = 1 }
8 1     1   5 use Object::HashBase;
  1         2  
  1         3  
9 1     1   344 use Object::HashBase::Test;
  1         2  
  1         496  
10              
11             my $hb_file = $INC{'Object/HashBase.pm'};
12             my $t_file = $INC{'Object/HashBase/Test.pm'};
13              
14             sub inline {
15 1     1 0 593 my ($prefix, $version) = @_;
16 1 50       4 $version = $VERSION unless defined $version;
17              
18 1         2 my $path = $prefix;
19 1         5 $path =~ s{::}{/}g;
20 1         3 $path = "lib/$path";
21 1         1 my $partial = '';
22              
23 1         5 for my $part (split /\//, "$path") {
24 3         8 $partial = join '/', grep { $_ } $partial, $part;
  6         16  
25 3 50       118 mkdir($partial) unless -d $partial;
26             }
27              
28 1         5 $path .= "/HashBase.pm";
29              
30 1 50       36 mkdir('t') unless -d 't';
31              
32 1 50       51 open(my $hbf, '>', $path) or die "Could not create '$path': $!";
33 1 50       42 open(my $tf, '>', 't/HashBase.t') or die "Could not create 't/HashBase.t': $!";
34              
35 1 50       30 open(my $hin, '<', $hb_file) or die "Could not open '$hb_file': $!";
36 1 50       28 open(my $tin, '<', $t_file) or die "Could not open '$t_file': $!";
37              
38              
39 1         10 print $hbf <<" EOT";
40             package $prefix\::HashBase;
41             use strict;
42             use warnings;
43              
44             our \$VERSION = '$version';
45              
46             #################################################################
47             # #
48             # This is a generated file! Do not modify this file directly! #
49             # Use hashbase_inc.pl script to regenerate this file. #
50             # The script is part of the Object::HashBase distribution. #
51             # Note: You can modify the version number above this comment #
52             # if needed, that is fine. #
53             # #
54             #################################################################
55              
56             {
57             no warnings 'once';
58             \$$prefix\::HashBase::HB_VERSION = '$Object::HashBase::VERSION';
59             \*$prefix\::HashBase::ATTR_SUBS = \\\%Object::HashBase::ATTR_SUBS;
60             \*$prefix\::HashBase::ATTR_LIST = \\\%Object::HashBase::ATTR_LIST;
61             \*$prefix\::HashBase::VERSION = \\\%Object::HashBase::VERSION;
62             \*$prefix\::HashBase::CAN_CACHE = \\\%Object::HashBase::CAN_CACHE;
63             }
64              
65             EOT
66              
67 1         12 print $tf <<" EOT";
68             use strict;
69             use warnings;
70              
71             use Test::More;
72              
73             EOT
74              
75 1         2 my $writing = 0;
76 1         25 while (my $line = <$hin>) {
77 469 100       689 if ($line =~ m/<-- START -->/) {
78 1         20 $writing = 1;
79 1         10 next;
80             }
81              
82 468 100       625 if ($line =~ m/^=head1 INCLUDING IN YOUR DIST$/) {
83 1         2 $writing = 0;
84 1         4 print $hbf <<" EOT";
85             =head1 THIS IS A BUNDLED COPY OF HASHBASE
86              
87             This is a bundled copy of L. This file was generated using
88             the
89             C<$0>
90             script.
91              
92             EOT
93 1         2 next;
94             }
95 467 100       624 if ($line =~ m/^=head1 /) {
96 11         14 $writing = 1;
97             }
98              
99 467 100       596 next unless $writing;
100              
101 441         528 $line =~ s/\QObject::\E/$prefix\::/g;
102              
103 441         866 print $hbf $line;
104             }
105              
106 1         3 $writing = 0;
107 1         21 while (my $line = <$tin>) {
108 265 100       388 if ($line =~ m/<-- START -->/) {
109 1         2 $writing = 1;
110 1         2 next;
111             }
112              
113 264 100       351 next unless $writing;
114              
115 241         319 $line =~ s/\QObject::HashBase::Test::\E/main\::/g;
116 241         287 $line =~ s/\QObject::\E/$prefix\::/g;
117 241         467 print $tf $line;
118             }
119              
120 1         25 close($hbf);
121 1         35 close($tf);
122             }
123              
124             1;