File Coverage

blib/lib/ODS/Utils.pm
Criterion Covered Total %
statement 66 66 100.0
branch 7 8 87.5
condition 4 4 100.0
subroutine 16 16 100.0
pod 0 5 0.0
total 93 99 93.9


line stmt bran cond sub pod time code
1             package ODS::Utils;
2              
3 74     74   448 use YAOO;
  74         154  
  74         368  
4 74     74   20722 no strict 'refs';
  74         97  
  74         2394  
5 74     74   38107 use Data::GUID;
  74         1200218  
  74         372  
6 74     74   41788 use File::Copy qw/move/;
  74         147467  
  74         3719  
7 74     74   456 use Carp qw/croak/;
  74         88  
  74         2616  
8 74     74   319 use Scalar::Util qw//;
  74         138  
  74         1174  
9 74     74   36761 use Data::Dumper qw/Dumper/;
  74         378589  
  74         9397  
10              
11             our ( %EX, %EX2);
12              
13             BEGIN {
14 74     74   742 %EX = (
15             load => [qw/all/],
16             clone => [qw/all/],
17             unique_class_name => [qw/all/],
18             build_temp_class => [qw/all/],
19             move => [qw/all/],
20             deep_unblessed => [qw/all/],
21             croak => [qw/error/],
22             Dumper => [qw/error/]
23             );
24 74         301 for my $ex (keys %EX) {
25 585         529 for (@{ $EX{$ex} }) {
  584         798  
26 584         562 push @{ $EX2{$_} }, $ex;
  584         30689  
27             }
28             }
29             }
30              
31             sub import {
32 568     568   1586 my ($self, @functions) = @_;
33              
34 568         1619 my $caller = caller();
35              
36 568         1269 for my $fun (@functions) {
37 1002 100       9979 if ($EX{$fun}) {
    50          
38 640         789 YAOO::make_keyword($caller, $fun, *{"${self}::${fun}"});
  640         3148  
39             } elsif ($EX2{$fun}) {
40 362         557 for (@{ $EX2{$fun} }) {
  362         896  
41 724         3993 YAOO::make_keyword($caller, $_, *{"${self}::${_}"});
  724         2148  
42             }
43             }
44             }
45              
46             }
47              
48             sub clone {
49 39378     39378 0 45987 my ($c) = @_;
50 39378         54743 my $n = bless YAOO::deep_clone_ordered_hash($c), ref $c;
51 39378         4331463 return $n;
52             }
53              
54             sub load {
55 1917     1917 0 7049 my ($module) = shift;
56 1917         8273 (my $require = $module) =~ s/\:\:/\//g;
57 1917         300079 require $require . '.pm';
58 1747         42251 return $module;
59             }
60              
61             sub unique_class_name {
62 1862     1862 0 29868 return 'A' . join("", split("-", Data::GUID->new->as_string()));
63             }
64              
65             sub build_temp_class {
66 150     150 0 500 my ($class) = @_;
67 150         466 load $class;
68 150         1156 my $temp = $class . '::' . unique_class_name();
69 150         44707 my $c = sprintf(
70             q|
71             package %s;
72             use YAOO;
73             extends '%s';
74             1;
75             |, $temp, $class );
76 150     72   19635 eval $c;
  72     70   559  
  72         85  
  72         336  
  70         21487  
  70         340  
  70         798  
77 150         780 return $temp;
78             }
79              
80             sub deep_unblessed {
81 16     16 0 22 my ($obj) = @_;
82              
83 16 100 100     75 if ((ref($obj) || "SCALAR") !~ m/ARRAY|HASH|SCALAR/) {
84 8         12 $obj = {%{ $obj }};
  8         15  
85             }
86              
87 16 100 100     51 if ((ref($obj) || "") eq 'HASH') {
88 8         11 for my $key (keys %{ $obj }) {
  8         15  
89 12         23 $obj->{$key} = deep_unblessed($obj->{$key});
90             }
91             }
92              
93 16         29 return $obj;
94             }
95              
96             1;