Eulerian/EDW/Sql/Array.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 66 CC 2 SCAR 11.0
CC
2
Cov
0%
str
6.0
new
2.0
push
2.0
CRAP 3.0
1 #!/usr/bin/perl
2 ###############################################################################
3 #
4 # @brief Eulerian EDW Sql Array class definition.
5 #
6 # @file API/Eulerian/EDW/Sql/Array.pm
7 #
8 # @author x.thorillon@eulerian.com
9 #
10 ###############################################################################
11 #
12 # Enforce compilor rules.
13 #
14 use strict; use warnings;
15 #
16 # Setup Package path.
17 #
18 package API::Eulerian::EDW::Sql::Array;
19 #
20 # @brief Allocate and initialize a new Sql::Array instance.
21 #
22 # @param $proto - Class name.
23 # @param $setup - Alias initial attributes values.
24 # sep : Array values separator.
25 # crlf : Array values CRLF,
26 # tab : Array values tabulation.
27 #
28 # @return Array instance.
29 #
30 sub new
31 {
32 my $proto = shift;
33 my $class = ref( $proto ) || $proto;
34 my $setup = shift;
35 return bless( {
36 items => [],
37 sep => $setup->{ sep } || '',
38 crlf => $setup->{ crlf } || '',
39 tab => $setup->{ tab } || '',
40 }
41 );
42 }
43 #
44 # @brief Add item into SQL array.
45 #
46 # @param $self - Self.
47 # @param $item - Item.
48 #
49 # @return Array items count.
50 #
51 sub push
52 {
53 my ( $self, $item ) = @_;
54 my $items = $self->{ items };
55 push( @$items, $item );
56 return scalar( @$items );
57 }
58 #
59 # @brief Get item at given index.
60 #
61 # @param $self - Self.
62 # @param $index - Item index.
63 #
64 # @return Item.
65 #
66 sub get
67 {
68 my ( $self, $index ) = @_;
69 my $items = $self->{ items };
70 return $items->[ $index ];
71 }
72 #
73 # @brief Get count of items in the array.
74 #
75 # @param $self - Self.
76 #
77 # @return Items count.
78 #
79 sub count
80 {
81 my ( $self ) = @_;
82 my $items = $self->{ items };
83 return scalar( @$items );
84 }
85 #
86 # @brief Stringify Array values.
87 #
88 # @param $self - Self.
89 #
90 # @return Stringified Array values.
91 #
92 sub str
93 {
94 my ( $self ) = @_;
95 my $items = $self->{ items };
96 my $nitems = scalar( @$items );
97 my $str = '';
98 my $iitem;
99 my $item;
100  
101 if( $nitems ) {
102 for $iitem ( 0 ... $nitems - 2 ) {
103 $item = $items->[ $iitem ];
104 $str .= $self->{ tab };
105 $str .= $item->str();
106 $str .= $self->{ sep };
107 $str .= $self->{ crlf };
108 }
109 $item = $items->[ $nitems - 1 ];
110 $str .= $self->{ tab };
111 $str .= $item->str();
112 $str .= $self->{ crlf };
113 }
114  
115 return $str;
116 }
117 #
118 # End up module properly
119 #
120 1;
121  
122 __END__