Changeset 2607 in ProjectBuilder for devel/pb-modules/lib/ProjectBuilder/YAML.pm


Ignore:
Timestamp:
Apr 7, 2020, 1:03:01 AM (4 years ago)
Author:
Bruno Cornec
Message:

Fix YAML pb_Dump function, adds a test for embedded YAML, export PBCONFVER from Version and fix sles 10 sudoers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-modules/lib/ProjectBuilder/YAML.pm

    r2598 r2607  
    77# We rename it here to allow embedded usage during setupv
    88# when no YAML implementation is available on the target system
     9# We also made modifications to avoid object usage conflicting in setupv
     10# and changed pb_Dump to adapt to new parameters
    911#
    1012package ProjectBuilder::YAML;
     
    116118sub _load_file {
    117119    # Check the file
    118     #print("SPECIAL: loadfile ".Dumper(@_)."\n");
     120    #print("SPECIAL: loadfile ".Data::Dumper::Dumper(@_)."\n");
    119121    my $file = shift or _error( 'You did not specify a file name' );
    120122    _error( "File '$file' does not exist" )
     
    157159# Create an object from a string
    158160sub _load_string {
    159         #print("SPECIAL: loadstring ".Dumper(@_)."\n");
     161        #print("SPECIAL: loadstring ".Data::Dumper::Dumper(@_)."\n");
    160162    my $self   = [];
    161163    my $string = $_[0];
     
    271273# Load a YAML scalar string to the actual Perl scalar
    272274sub _load_scalar {
    273         #print("SPECIAL: loadscalar ".Dumper(@_)."\n");
     275        #print("SPECIAL: loadscalar ".Data::Dumper::Dumper(@_)."\n");
    274276    my ($string, $indent, $lines) = @_;
    275277
     
    341343# Load an array
    342344sub _load_array {
    343         #print("SPECIAL: loadarray ".Dumper(@_)."\n");
     345        #print("SPECIAL: loadarray ".Data::Dumper::Dumper(@_)."\n");
    344346    my ($array, $indent, $lines) = @_;
    345347
     
    424426# Load a hash
    425427sub _load_hash {
    426         #print("SPECIAL: loadhash ".Dumper(@_)."\n");
     428        #print("SPECIAL: loadhash ".Data::Dumper::Dumper(@_)."\n");
    427429    my ($hash, $indent, $lines) = @_;
    428430
     
    512514
    513515
    514 ###
    515 # Dumper functions:
    516 
    517516# Save an object to a string
    518517sub _dump_string {
    519         #print("SPECIAL: dumpstring ".Dumper(@_)."\n");
    520     my $self = shift;
    521     return '' unless ref $self && @$self;
     518    my $self = $_[0];
     519    return '' unless ref $self && %$self;
     520
     521    #print("SPECIAL: dumpstring ".Data::Dumper::Dumper($self)."\n");
    522522
    523523    # Iterate over the documents
    524524    my $indent = 0;
    525525    my @lines  = ();
     526    push @lines, '---';
    526527
    527528    eval {
    528         foreach my $cursor ( @$self ) {
    529             push @lines, '---';
     529        foreach my $c ( sort keys %$self ) {
     530            my $cursor = $self->{$c};
     531            #print("SPECIAL: c, cursor ".Data::Dumper::Dumper($c,$cursor)."\n");
     532            push(@lines, _dump_scalar( $c, $cursor).':');
     533            $indent += 1;
    530534
    531535            # An empty document
     
    535539            # A scalar document
    536540            } elsif ( ! ref $cursor ) {
    537                 $lines[-1] .= ' ' . _dump_scalar( $cursor );
     541                    #print("SPECIAL: found scalar \n");
     542                $lines[-1] .= ' ' . _dump_scalar( $c, $cursor );
     543                #print("SPECIAL: dumpscalar returns".Data::Dumper::Dumper($lines[-1])."\n");
    538544
    539545            # A list at the root
    540546            } elsif ( ref $cursor eq 'ARRAY' ) {
     547                    #print("SPECIAL: found array \n");
    541548                unless ( @$cursor ) {
    542549                    $lines[-1] .= ' []';
    543550                    next;
    544551                }
    545                 push @lines, _dump_array( $cursor, $indent, {} );
     552                push @lines, _dump_array( $c, $cursor, $indent, {} );
    546553
    547554            # A hash at the root
    548555            } elsif ( ref $cursor eq 'HASH' ) {
     556                    #print("SPECIAL: found hash \n");
    549557                unless ( %$cursor ) {
    550558                    $lines[-1] .= ' {}';
    551559                    next;
    552560                }
    553                 push @lines, _dump_hash( $cursor, $indent, {} );
     561                push @lines, _dump_hash( $c, $cursor, $indent, {} );
    554562
    555563            } else {
    556564                die \("Cannot serialize " . ref($cursor));
    557565            }
     566            #print("SPECIAL: lines ".Data::Dumper::Dumper(@lines)."\n");
     567            $indent -= 1;
    558568        }
    559569    };
     
    574584
    575585sub _dump_scalar {
    576         #print("SPECIAL: dumpscalar ".Dumper(@_)."\n");
    577     my $string = $_[1];
    578     my $is_key = $_[2];
     586        #print("SPECIAL: dumpscalar ".Data::Dumper::Dumper(@_)."\n");
     587    my $string = $_[0];
     588    #print("SPECIAL: string ".Data::Dumper::Dumper($string)."\n");
     589    my $is_key = $_[1];
    579590    # Check this before checking length or it winds up looking like a string!
    580591    my $has_string_flag = _has_internal_string_value($string);
     592    #print("SPECIAL: hasstring ".Data::Dumper::Dumper($has_string_flag)."\n");
    581593    return '~'  unless defined $string;
    582594    return "''" unless length  $string;
     
    608620
    609621sub _dump_array {
    610         #print("SPECIAL: dumparray ".Dumper(@_)."\n");
     622        #print("SPECIAL: dumparray ".Data::Dumper::Dumper(@_)."\n");
    611623    my ($array, $indent, $seen) = @_;
    612624    if ( $seen->{refaddr($array)}++ ) {
     
    648660
    649661sub _dump_hash {
    650         #print("SPECIAL: dumphash ".Dumper(@_)."\n");
    651     my ($hash, $indent, $seen) = @_;
     662        #print("SPECIAL: dumphash ".Data::Dumper::Dumper(@_)."\n");
     663    my ($c, $hash, $indent, $seen) = @_;
    652664    if ( $seen->{refaddr($hash)}++ ) {
    653665        die \"ProjectBuilder::YAML does not support circular references";
     
    683695            die \"ProjectBuilder::YAML does not support $type references";
    684696        }
     697        #print("SPECIAL: lines ".Data::Dumper::Dumper(@lines)."\n");
    685698    }
    686699
     
    700713    require Carp;
    701714    $errstr = $_[0];
    702     #print("SPECIAL: error: ".Dumper(@_)."\n");
     715    #print("SPECIAL: error: ".Data::Dumper::Dumper(@_)."\n");
    703716    #$errstr =~ s/ at \S+ line \d+.*//;
    704717    Carp::croak( $errstr );
Note: See TracChangeset for help on using the changeset viewer.