File Coverage

blib/lib/Siebel/Srvrmgr/ListParser/Output/Tabular/Struct/Delimited.pm
Criterion Covered Total %
statement 22 22 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 32 33 96.9


line stmt bran cond sub pod time code
1             package Siebel::Srvrmgr::ListParser::Output::Tabular::Struct::Delimited;
2              
3 29     29   4508 use Moose 2.0401;
  29         760  
  29         274  
4 29     29   254640 use Carp;
  29         100  
  29         2834  
5 29     29   242 use namespace::autoclean 0.13;
  29         778  
  29         277  
6              
7             extends 'Siebel::Srvrmgr::ListParser::Output::Tabular::Struct';
8             our $VERSION = '0.29'; # VERSION
9              
10             =head1 NAME
11              
12             Siebel::Srvrmgr::ListParser::Output::Tabular::Struct::Delimited - subclasses to parse delimited output from srvrmgr
13              
14             =head1 DESCRIPTION
15              
16             This class is a subclass of L<Siebel::Srvrmgr::ListParser::Output::Tabular::Struct> to parse output from C<srvrmgr> that
17             is created with a field delimiter character.
18              
19             =head1 ATTRIBUTES
20              
21             =head2 trimmer
22              
23             A code reference to remove additional spaces from the fields attributes data.
24              
25             It is created automatically by a L<Moose> builder.
26              
27             =cut
28              
29             has trimmer => (
30             is => 'ro',
31             isa => 'CodeRef',
32             reader => 'get_trimmer',
33             builder => '_build_trimmer'
34             );
35              
36             # :WORKAROUND:01-01-2014 18:42:35:: could not user super() because
37             # it was using a "default" value after calling _set_header_regex
38             override '_build_header_regex' => sub {
39              
40             my $self = shift;
41              
42             my $new_sep = '(\s+)?' . $self->get_col_sep();
43              
44             $self->_set_header_regex( join( $new_sep, @{ $self->get_header_cols() } ) );
45              
46             };
47              
48             # :WORKAROUND:01-01-2014 17:43:39:: used closure to compile the regex only once
49             sub _build_trimmer {
50              
51 77     77   376 my $r_spaces = qr/\s+$/;
52              
53             return sub {
54              
55 21940     21940   50883 my $values_ref = shift;
56              
57 21940         46096 for ( my $i = 0 ; $i <= $#{$values_ref} ; $i++ ) {
  298852         857945  
58              
59 276912         1484637 $values_ref->[$i] =~ s/$r_spaces//;
60              
61             }
62              
63 21940         53026 return 1;
64              
65             }
66              
67 77         3890 }
68              
69             =pod
70              
71             =head2 get_fields
72              
73             Overrided method from parent class.
74              
75             Expects a string as parameter and returns a array reference with the fields values extracted.
76              
77             =cut
78              
79             override 'get_fields' => sub {
80              
81             my $self = shift;
82             my $line = shift;
83              
84             my $fields_ref = $self->split_fields($line);
85              
86             $self->get_trimmer()->($fields_ref);
87              
88             return $fields_ref;
89              
90             };
91              
92             =pod
93              
94             =head2 BUILD
95              
96             This L<Moose> BUILD implementation does some additional validations during object creation
97             and also escapes the field delimiter character to be used in regular expressions.
98              
99             =cut
100              
101             sub BUILD {
102              
103 77     77 1 224 my $self = shift;
104 77         198 my $args = shift;
105              
106             confess 'col_sep is a required attribute for ' . __PACKAGE__ . ' instances'
107 77 50       326 unless ( defined( $args->{col_sep} ) );
108              
109 77         3863 my $sep = $self->get_col_sep();
110              
111             #escape the char to be used in a regex
112 77         3631 $self->_set_col_sep( '\\' . $sep );
113              
114             }
115              
116             =pod
117              
118             =head2 define_fields_pattern
119              
120             Method overrided from the superclass.
121              
122             Since this classes doesn't use the concept of "fields pattern" for parsing,
123             it simply returns C<true>, making this class compatible with parent class interface.
124              
125             =cut
126              
127             sub define_fields_pattern {
128              
129 77     77 1 1759 return 1;
130              
131             }
132              
133             =head1 SEE ALSO
134              
135             =over
136              
137             =item *
138              
139             L<Siebel::Srvrmgr::ListParser::Output::Tabular>
140              
141             =item *
142              
143             L<Moose>
144              
145             =item *
146              
147             L<Siebel::Srvrmgr::ListParser::Output::Tabular::Struct>
148              
149             =back
150              
151             =head1 AUTHOR
152              
153             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
154              
155             =head1 COPYRIGHT AND LICENSE
156              
157             This software is copyright (c) 2013 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
158              
159             This file is part of Siebel Monitoring Tools.
160              
161             Siebel Monitoring Tools is free software: you can redistribute it and/or modify
162             it under the terms of the GNU General Public License as published by
163             the Free Software Foundation, either version 3 of the License, or
164             (at your option) any later version.
165              
166             Siebel Monitoring Tools is distributed in the hope that it will be useful,
167             but WITHOUT ANY WARRANTY; without even the implied warranty of
168             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
169             GNU General Public License for more details.
170              
171             You should have received a copy of the GNU General Public License
172             along with Siebel Monitoring Tools. If not, see L<http://www.gnu.org/licenses/>.
173              
174             =cut
175              
176             __PACKAGE__->meta->make_immutable;