File Coverage

blib/lib/Siebel/Srvrmgr/ListParser/Output/Tabular/Struct/Fixed.pm
Criterion Covered Total %
statement 22 24 91.6
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 31 35 88.5


line stmt bran cond sub pod time code
1             package Siebel::Srvrmgr::ListParser::Output::Tabular::Struct::Fixed;
2 29     29   2843 use Moose 2.0401;
  29         624  
  29         258  
3 29     29   248405 use namespace::autoclean 0.13;
  29         795  
  29         295  
4             extends 'Siebel::Srvrmgr::ListParser::Output::Tabular::Struct';
5             our $VERSION = '0.29'; # VERSION
6              
7             =pod
8              
9             =head1 NAME
10              
11             Siebel::Srvrmgr::ListParser::Output::Tabular::Struct::Fixed - subclass to parse fixed width output from srvrmgr
12              
13             =head1 DESCRIPTION
14              
15             This class is a subclass of L<Siebel::Srvrmgr::ListParser::Output::Tabular::Struct> to parse fixed width output from C<srvrmgr>.
16              
17             =head1 ATTRIBUTES
18              
19             =head2 fields_pattern
20              
21             This is a read-only attribute which is defined internally by invoking the C<define_fields_pattern> method during parsing execution.
22              
23             It is a string representing the pattern of the fields to be used with C<unpack> function.
24              
25             =cut
26              
27             has fields_pattern => (
28             is => 'ro',
29             isa => 'Str',
30             reader => 'get_fields_pattern',
31             writer => '_set_fields_pattern'
32             );
33              
34             sub _build_col_sep {
35 110     110   339 my $self = shift;
36 110         5567 $self->_set_col_sep('\s{2,}');
37             }
38              
39             =pod
40              
41             =head1 METHODS
42              
43             =head2 define_fields_pattern
44              
45             Overrided from the parent class.
46              
47             Based on the first two rows of a C<srvrmgr> output with fixed width format, it will define
48             the fields pattern to be used with C<unpack> to retrieve the fields values.
49              
50             Expects the "------------" line under the header with the fields names.
51              
52             =cut
53              
54             sub define_fields_pattern {
55 110     110 1 2226 my ( $self, $line ) = @_;
56 110         5429 my $separator = $self->get_col_sep();
57 110         770 my $comp_sep = qr/$separator/;
58              
59             # :TODO:30-12-2013:: some logging would ne nice here
60 110 50       1005 if ( $line =~ $comp_sep ) {
61 110         1700 my @columns = split( /$separator/, $line );
62 110         343 my $pattern;
63              
64 110         380 foreach my $column (@columns) {
65             # :WARNING :09/05/2013 12:19:37:: + 2 because of the spaces after the "---" that will be trimmed
66 1212         2964 $pattern .= 'A' . ( length($column) + 2 );
67             }
68              
69 110         6179 $self->_set_fields_pattern($pattern);
70 110         807 return 1;
71              
72             }
73             else {
74 0         0 return 0;
75             }
76             }
77              
78             =pod
79              
80             =head2 get_fields
81              
82             Overrided from parent class.
83              
84             Returns the fields values as an array reference.
85              
86             Expects a string with fields values to be parsed.
87              
88             =cut
89              
90             sub get_fields {
91 27869     27869 1 70512 my ( $self, $line ) = @_;
92              
93 27869 50       1419068 if ( defined( $self->get_fields_pattern() ) ) {
94 27869         1379676 my @fields = unpack( $self->get_fields_pattern(), $line );
95 27869         111891 return \@fields;
96             }
97             else {
98 0           confess
99             'cannot procede without being able to define the fields pattern for parsing: check if command output configuration is as expected by the parsing class';
100             }
101             }
102              
103             =head1 SEE ALSO
104              
105             =over
106              
107             =item *
108              
109             L<Siebel::Srvrmgr::ListParser::Output::Tabular>
110              
111             =item *
112              
113             L<Moose>
114              
115             =item *
116              
117             L<Siebel::Srvrmgr::ListParser::Output::Tabular::Struct>
118              
119             =back
120              
121             =head1 AUTHOR
122              
123             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
124              
125             =head1 COPYRIGHT AND LICENSE
126              
127             This software is copyright (c) 2013 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
128              
129             This file is part of Siebel Monitoring Tools.
130              
131             Siebel Monitoring Tools is free software: you can redistribute it and/or modify
132             it under the terms of the GNU General Public License as published by
133             the Free Software Foundation, either version 3 of the License, or
134             (at your option) any later version.
135              
136             Siebel Monitoring Tools is distributed in the hope that it will be useful,
137             but WITHOUT ANY WARRANTY; without even the implied warranty of
138             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
139             GNU General Public License for more details.
140              
141             You should have received a copy of the GNU General Public License
142             along with Siebel Monitoring Tools. If not, see L<http://www.gnu.org/licenses/>.
143              
144             =cut
145              
146             __PACKAGE__->meta->make_immutable;