ConfigSorted.pm 2.24 KB
 Stefan Tauner committed May 04, 2018 1 2 3 4 #----------------------------------------------------------------------- # Fault InJection Instrumenter (FIJI) # https://embsys.technikum-wien.at/projects/vecs/fiji #  Stefan Tauner committed May 04, 2018 5 6 7 8 # The creation of this file has been supported by the publicly funded # R&D project Josef Ressel Center for Verification of Embedded Computing # Systems (VECS) managed by the Christian Doppler Gesellschaft (CDG). #  Stefan Tauner committed May 04, 2018 9 10 11 # Authors: # Christian Fibich # Stefan Tauner  Stefan Tauner committed May 04, 2018 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 # # This module is free software; you can redistribute it and/or modify # it under the same terms as Perl itself. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # See the LICENSE file for more details. #----------------------------------------------------------------------- ## @file ConfigSorted.pm # @brief Contains class \ref FIJI::ConfigSorted ## @class FIJI::ConfigSorted # @brief Variation of Config::Simple that produces sorted sections and entries within a section  Christian Fibich committed May 04, 2018 29 30 package FIJI::ConfigSorted;  Stefan Tauner committed May 04, 2018 31 32 33 use strict; use warnings;  Stefan Tauner committed May 04, 2018 34 use Config::Simple;  Stefan Tauner committed May 04, 2018 35 use Sort::Naturally;  Stefan Tauner committed May 04, 2018 36   Christian Fibich committed May 04, 2018 37 38 39 40 # Set version information use vars qw($VERSION);$VERSION = '0.1';  Stefan Tauner committed May 04, 2018 41 use base qw(Config::Simple);  Christian Fibich committed May 04, 2018 42 43 44 45 46 47 48  # generates a writable string sub as_string { my $self = shift; my$syntax = $self->{_SYNTAX} or die "'_SYNTAX' is not defined"; my$sub_syntax = $self->{_SUB_SYNTAX} || '';  Christian Fibich committed May 04, 2018 49 50 51  my$currtime = localtime; my $STRING = undef; if ($syntax eq 'ini') {  Christian Fibich committed May 04, 2018 52 53  $STRING .= "; FIJI::ConfigSorted$VERSION\n"; $STRING .= ";$currtime\n\n";  Stefan Tauner committed May 04, 2018 54  for my $block_name (nsort(keys %{$self->{_DATA}})) {  Christian Fibich committed May 04, 2018 55  my $key_values =$self->{_DATA}->{$block_name};  Christian Fibich committed May 04, 2018 56  unless ($sub_syntax eq 'simple-ini') {  Christian Fibich committed May 04, 2018 57 58 59 60  $STRING .= sprintf("[%s]\n",$block_name); } for my $key (sort keys %{$key_values}) { my $value =$key_values->{$key};  Stefan Tauner committed May 04, 2018 61  my$values = join($self->SUPER::WRITE_DELIM, map {$self->SUPER::quote_values($_) } @$value);  Christian Fibich committed May 04, 2018 62  $STRING .= sprintf("%s=%s\n",$key, $values);  Christian Fibich committed May 04, 2018 63 64 65 66 67 68 69 70 71  }$STRING .= "\n"; } } $STRING .= "\n"; return$STRING; } 1;