script/insert_pod.pl untested

filter: Statementstmt 0.0% 0 / 78 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 113 CC 8 SCAR 29.4
CC
8
Cov
0%
replace_true_to_pod
42.0
main
12.0
BEGIN
2.0
CRAP 18.9
1 #!/usr/bin/env perl
2  
3 use strict;
4 use warnings;
5 use autodie;
6 use File::Spec;
7 use FindBin;
8 use Path::Class qw/dir/;
9 use YAML;
10  
11 &main();
12  
13 sub main {
14 my $base_dir = File::Spec->rel2abs($FindBin::Bin);
15 my $dir = dir($base_dir.'/../lib/Jubatus/');
16 my $pod_tmpl_dir = $base_dir.'/../tmpl/';
17 my @use_modules;
18 my @get_clients;
19 my @module_names;
20 while (my $dir_path = $dir->next) {
21 my $subdir = dir($dir_path);
22 my $dir = $subdir->{dirs}->[-1];
23 next if ($dir =~ m|^.+\.pm$|);
24 while (my $subdir_path = $subdir->next) {
25 if ((exists $subdir_path->{file}) && ($subdir_path->{file} =~ m|Client.pm|)){
26 my $module_name = $subdir_path->{dir}->{dirs}->[-1];
27 my $module_path = join "/",@{$subdir_path->{dir}->{dirs}};
28 {
29 my $pod_type = "client";
30 my $client_module_path = $module_path."/Client.pm";
31 my $is_replace = &replace_true_to_pod($module_name, $client_module_path, $pod_tmpl_dir, $pod_type);
32 }
33 {
34 my $pod_type = "types";
35 my $client_module_path = $module_path."/Types.pm";
36 my $is_replace = &replace_true_to_pod($module_name, $client_module_path, $pod_tmpl_dir, $pod_type);
37 }
38 }
39 }
40 }
41 return;
42 }
43  
44 sub replace_true_to_pod {
45 my ($module_name, $client_module_path, $pod_tmpl_dir, $pod_types) = @_;
46 my $module_name_nc = $module_name;
47 $module_name_nc =~ tr|[A-Z]|[a-z]|;
48 my $is_replaced = 0;
49 my $tmp_client_module_path = $client_module_path.".tmp";
50 my $pod_path = $pod_tmpl_dir."/".$module_name_nc."_".$pod_types.".pod";
51 if (-f $pod_path) {
52 open my $pod_in, "<:utf8", $pod_path;
53 open my $module_in, "<:utf8", $client_module_path;
54 open my $module_out, ">:utf8", $tmp_client_module_path;
55  
56 my @pod_lines = <$pod_in>;
57 my $pod = join "", @pod_lines;
58 my $is_package = 0;
59 while (my $line = <$module_in>) {
60 if (($is_package) && ($line =~ m|^1;$|)) {
61 print $module_out "1;\n";
62 print $module_out $pod;
63 }
64 else {
65 print $module_out $line;
66 }
67 if ($line =~ m|package Jubatus::.+::Client;|) {
68 $is_package = 1;
69 }
70 elsif ($line =~ m|package Jubatus::.+::Types;|) {
71 $is_package = 1;
72 }
73 }
74  
75 close $pod_in;
76 close $module_in;
77 close $module_out;
78  
79 my $is_mv = system("mv $tmp_client_module_path $client_module_path");
80 $is_replaced = 1 if (0 == $is_mv);
81 } else {
82 }
83 return $is_replaced;
84 }