Changeset 2495 in ProjectBuilder for devel


Ignore:
Timestamp:
Mar 31, 2020, 9:03:48 PM (6 years ago)
Author:
Bruno Cornec
Message:

Rename functions to avoid clashes

File:
1 edited

Legend:

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

    r2484 r2495  
    22use strict;
    33use warnings;
    4 package YAML::Tiny; # git description: v1.72-7-g8682f63
     4# Original is YAML::Tiny git description: v1.72-7-g8682f63
     5# We rename it here to allow embedded usage during setupv
     6# when no YAML implementation is available on the target system
     7#
     8package ProjectBuilder::YAML;
    59# XXX-INGY is 5.8.1 too old/broken for utf8?
    610# XXX-XDG Lancaster consensus was that it was sufficient until
    … …  
    1014
    1115#####################################################################
    12 # The YAML::Tiny API.
     16# The ProjectBuilder::YAML API.
    1317#
    1418# These are the currently documented API functions/methods and
    … …  
    1721use Exporter;
    1822our @ISA       = qw{ Exporter  };
    19 our @EXPORT    = qw{ Load Dump };
    20 our @EXPORT_OK = qw{ LoadFile DumpFile freeze thaw };
     23our @EXPORT    = qw{ pb_Load pb_Dump };
     24our @EXPORT_OK = qw{ pb_LoadFile pb_DumpFile freeze thaw };
    2125
    2226###
    2327# Functional/Export API:
    2428
    25 sub Dump {
    26     return YAML::Tiny->new(@_)->_dump_string;
     29sub pb_Dump {
     30    return ProjectBuilder::YAML->new(@_)->_dump_string;
    2731}
    2832
    … …  
    3034# XXX-XDG I think first would seem more natural, but I don't know
    3135# that it's worth changing now
    32 sub Load {
    33     my $self = YAML::Tiny->_load_string(@_);
     36sub pb_Load {
     37    my $self = ProjectBuilder::YAML->_load_string(@_);
    3438    if ( wantarray ) {
    3539        return @$self;
    … …  
    4347# XXX-XDG I don't think so.  I'd support deprecating them.
    4448BEGIN {
    45     *freeze = \&Dump;
    46     *thaw   = \&Load;
    47 }
    48 
    49 sub DumpFile {
     49    *freeze = \&pb_Dump;
     50    *thaw   = \&pb_Load;
     51}
     52
     53sub pb_DumpFile {
    5054    my $file = shift;
    51     return YAML::Tiny->new(@_)->_dump_file($file);
    52 }
    53 
    54 sub LoadFile {
     55    return ProjectBuilder::YAML->new(@_)->_dump_file($file);
     56}
     57
     58sub pb_LoadFile {
    5559    my $file = shift;
    56     my $self = YAML::Tiny->_load_file($file);
     60    my $self = ProjectBuilder::YAML->_load_file($file);
    5761    if ( wantarray ) {
    5862        return @$self;
    … …  
    6771# Object Oriented API:
    6872
    69 # Create an empty YAML::Tiny object
     73# Create an empty ProjectBuilder::YAML object
    7074# XXX-INGY Why do we use ARRAY object?
    7175# NOTE: I get it now, but I think it's confusing and not needed.
    … …  
    7377#
    7478# XXX-XDG I don't support changing it yet.  It's a very well-documented
    75 # "API" of YAML::Tiny.  I'd support deprecating it, but Adam suggested
     79# "API" of ProjectBuilder::YAML.  I'd support deprecating it, but Adam suggested
    7680# we not change it until YAML.pm's own OO API is established so that
    7781# users only have one API change to digest, not two
    … …  
    8690# characters/strings. These take the data to/from storage to native
    8791# Perl objects, which the terms dump and load are meant. As long as
    88 # this is a legacy quirk to YAML::Tiny it's ok, but I'd prefer not
     92# this is a legacy quirk to ProjectBuilder::YAML it's ok, but I'd prefer not
    8993# to add new {read,write}_* methods to this API.
    9094
    … …  
    134138# XXX-INGY
    135139# I(ngy) need to decide if these values should be quoted in
    136 # YAML::Tiny or not. Probably yes.
     140# ProjectBuilder::YAML or not. Probably yes.
    137141
    138142# These 3 values have special meaning when unquoted and using the
    … …  
    158162
    159163#####################################################################
    160 # YAML::Tiny Implementation.
     164# ProjectBuilder::YAML Implementation.
    161165#
    162166# These are the private methods that do all the work. They may change
    … …  
    272276            } elsif ( ! $in_document && @$self ) {
    273277                # only the first document can be explicit
    274                 die \"YAML::Tiny failed to classify the line '$lines[0]'";
     278                die \"ProjectBuilder::YAML failed to classify the line '$lines[0]'";
    275279            } elsif ( $lines[0] =~ /^\s*\-(?:\s|$|-+$)/ ) {
    276280                # An array at the root
    … …  
    292296
    293297                # uncoverable statement
    294                 die \"YAML::Tiny failed to classify the line '$lines[0]'";
     298                die \"ProjectBuilder::YAML failed to classify the line '$lines[0]'";
    295299            }
    296300        }
    … …  
    345349    # Special cases
    346350    if ( $string =~ /^[\'\"!&]/ ) {
    347         die \"YAML::Tiny does not support a feature in line '$string'";
     351        die \"ProjectBuilder::YAML does not support a feature in line '$string'";
    348352    }
    349353    return {} if $string =~ /^{}(?:\s+\#.*)?\z/;
    … …  
    352356    # Regular unquoted string
    353357    if ( $string !~ /^[>|]/ ) {
    354         die \"YAML::Tiny found illegal characters in plain scalar: '$string'"
     358        die \"ProjectBuilder::YAML found illegal characters in plain scalar: '$string'"
    355359            if $string =~ /^(?:-(?:\s|$)|[\@\%\`])/ or
    356360                $string =~ /:(?:\s|$)/;
    … …  
    360364
    361365    # Error
    362     die \"YAML::Tiny failed to find multi-line scalar content" unless @$lines;
     366    die \"ProjectBuilder::YAML failed to find multi-line scalar content" unless @$lines;
    363367
    364368    # Check the indent depth
    … …  
    366370    $indent->[-1] = length("$1");
    367371    if ( defined $indent->[-2] and $indent->[-1] <= $indent->[-2] ) {
    368         die \"YAML::Tiny found bad indenting in line '$lines->[0]'";
     372        die \"ProjectBuilder::YAML found bad indenting in line '$lines->[0]'";
    369373    }
    370374
    … …  
    400404            return 1;
    401405        } elsif ( length($1) > $indent->[-1] ) {
    402             die \"YAML::Tiny found bad indenting in line '$lines->[0]'";
     406            die \"ProjectBuilder::YAML found bad indenting in line '$lines->[0]'";
    403407        }
    404408
    … …  
    436440
    437441            } else {
    438                 die \"YAML::Tiny failed to classify line '$lines->[0]'";
     442                die \"ProjectBuilder::YAML failed to classify line '$lines->[0]'";
    439443            }
    440444
    … …  
    457461
    458462        } else {
    459             die \"YAML::Tiny failed to classify line '$lines->[0]'";
     463            die \"ProjectBuilder::YAML failed to classify line '$lines->[0]'";
    460464        }
    461465    }
    … …  
    482486            return 1;
    483487        } elsif ( length($1) > $indent->[-1] ) {
    484             die \"YAML::Tiny found bad indenting in line '$lines->[0]'";
     488            die \"ProjectBuilder::YAML found bad indenting in line '$lines->[0]'";
    485489        }
    486490
    … …  
    506510        }
    507511        elsif ( $lines->[0] =~ /^\s*\?/ ) {
    508             die \"YAML::Tiny does not support a feature in line '$lines->[0]'";
     512            die \"ProjectBuilder::YAML does not support a feature in line '$lines->[0]'";
    509513        }
    510514        else {
    511             die \"YAML::Tiny failed to classify line '$lines->[0]'";
     515            die \"ProjectBuilder::YAML failed to classify line '$lines->[0]'";
    512516        }
    513517
    514518        if ( exists $hash->{$key} ) {
    515             warn "YAML::Tiny found a duplicate key '$key' in line '$lines->[0]'";
     519            warn "ProjectBuilder::YAML found a duplicate key '$key' in line '$lines->[0]'";
    516520        }
    517521
    … …  
    691695    my ($self, $array, $indent, $seen) = @_;
    692696    if ( $seen->{refaddr($array)}++ ) {
    693         die \"YAML::Tiny does not support circular references";
     697        die \"ProjectBuilder::YAML does not support circular references";
    694698    }
    695699    my @lines  = ();
    … …  
    720724
    721725        } else {
    722             die \"YAML::Tiny does not support $type references";
     726            die \"ProjectBuilder::YAML does not support $type references";
    723727        }
    724728    }
    … …  
    730734    my ($self, $hash, $indent, $seen) = @_;
    731735    if ( $seen->{refaddr($hash)}++ ) {
    732         die \"YAML::Tiny does not support circular references";
     736        die \"ProjectBuilder::YAML does not support circular references";
    733737    }
    734738    my @lines  = ();
    … …  
    760764
    761765        } else {
    762             die \"YAML::Tiny does not support $type references";
     766            die \"ProjectBuilder::YAML does not support $type references";
    763767        }
    764768    }
    … …  
    787791sub errstr {
    788792    require Carp;
    789     Carp::carp( "YAML::Tiny->errstr and \$YAML::Tiny::errstr is deprecated" )
     793    Carp::carp( "ProjectBuilder::YAML->errstr and \$ProjectBuilder::YAML::errstr is deprecated" )
    790794        unless $errstr_warned++;
    791795    $errstr;
    … …  
    802806use B;
    803807
    804 # XXX-INGY Is flock YAML::Tiny's responsibility?
     808# XXX-INGY Is flock ProjectBuilder::YAML's responsibility?
    805809# Some platforms can't flock :-(
    806810# XXX-XDG I think it is.  When reading and writing files, we ought
    … …  
    852856}
    853857
    854 delete $YAML::Tiny::{refaddr};
     858delete $ProjectBuilder::YAML::{refaddr};
    855859
    8568601;
    … …  
    873877=head1 NAME
    874878
    875 YAML::Tiny - Read/Write YAML files with as little code as possible
     879ProjectBuilder::YAML - Read/Write YAML files with as little code as possible
    876880
    877881=head1 VERSION
    … …  
    888892The original pure-Perl implementation L<YAML> costs just over 4 megabytes
    889893of memory to load. Just like with Windows F<.ini> files (3 meg to load) and
    890 CSS (3.5 meg to load) the situation is just asking for a B<YAML::Tiny>
     894CSS (3.5 meg to load) the situation is just asking for a B<ProjectBuilder::YAML>
    891895module, an incomplete but correct and usable subset of the functionality,
    892896in as little code as possible.
    893897
    894 Like the other C<::Tiny> modules, YAML::Tiny has no non-core dependencies,
     898Like the other C<::Tiny> modules, ProjectBuilder::YAML has no non-core dependencies,
    895899does not require a compiler to install, is back-compatible to Perl v5.8.1,
    896900and can be inlined into other modules if needed.
    … …  
    915919Read and write F<file.yml> like this:
    916920
    917     use YAML::Tiny;
     921    use ProjectBuilder::YAML;
    918922
    919923    # Open the config
    920     my $yaml = YAML::Tiny->read( 'file.yml' );
     924    my $yaml = ProjectBuilder::YAML->read( 'file.yml' );
    921925
    922926    # Get a reference to the first document
    … …  
    939943
    940944    # Create a new object with a single hashref document
    941     my $yaml = YAML::Tiny->new( { wibble => "wobble" } );
     945    my $yaml = ProjectBuilder::YAML->new( { wibble => "wobble" } );
    942946
    943947    # Add an arrayref document
    … …  
    958962=head1 DESCRIPTION
    959963
    960 B<YAML::Tiny> is a perl class for reading and writing YAML-style files,
     964B<ProjectBuilder::YAML> is a perl class for reading and writing YAML-style files,
    961965written with as little code as possible, reducing load time and memory
    962966overhead.
    … …  
    975979=for stopwords normalise
    976980
    977 L<YAML::Tiny> does not generate comments, it won't necessarily preserve the
     981L<ProjectBuilder::YAML> does not generate comments, it won't necessarily preserve the
    978982order of your hashes, and it will normalise if reading in and writing out
    979983again.
    … …  
    988992Features will only be added if they are human readable, and can be written
    989993in a few lines of code. Please don't be offended if your request is
    990 refused. Someone has to draw the line, and for YAML::Tiny that someone
     994refused. Someone has to draw the line, and for ProjectBuilder::YAML that someone
    991995is me.
    992996
    … …  
    995999a C compiler).
    9961000
    997 To restate, L<YAML::Tiny> does B<not> preserve your comments, whitespace,
     1001To restate, L<ProjectBuilder::YAML> does B<not> preserve your comments, whitespace,
    9981002or the order of your YAML data. But it should round-trip from Perl
    9991003structure to file and back again just fine.
    … …  
    10051009=head2 new
    10061010
    1007 The constructor C<new> creates a C<YAML::Tiny> object as a blessed array
     1011The constructor C<new> creates a C<ProjectBuilder::YAML> object as a blessed array
    10081012reference.  Any arguments provided are taken as separate documents
    10091013to be serialized.
    … …  
    10121016
    10131017The C<read> constructor reads a YAML file from a file name,
    1014 and returns a new C<YAML::Tiny> object containing the parsed content.
     1018and returns a new C<ProjectBuilder::YAML> object containing the parsed content.
    10151019
    10161020Returns the object on success or throws an error on failure.
    … …  
    10191023
    10201024The C<read_string> constructor reads YAML data from a character string, and
    1021 returns a new C<YAML::Tiny> object containing the parsed content.  If you have
     1025returns a new C<ProjectBuilder::YAML> object containing the parsed content.  If you have
    10221026read the string from a file yourself, be sure that you have correctly decoded
    10231027it into characters first.
    … …  
    10451049
    10461050Prior to version 1.57, some errors were fatal and others were available only
    1047 via the C<$YAML::Tiny::errstr> variable, which could be accessed via the
     1051via the C<$ProjectBuilder::YAML::errstr> variable, which could be accessed via the
    10481052C<errstr()> method.
    10491053
    … …  
    10571061=head1 FUNCTIONS
    10581062
    1059 YAML::Tiny implements a number of functions to add compatibility with
     1063ProjectBuilder::YAML implements a number of functions to add compatibility with
    10601064the L<YAML> API. These should be a drop-in replacement.
    10611065
    1062 =head2 Dump
    1063 
    1064   my $string = Dump(list-of-Perl-data-structures);
     1066=head2 pb_Dump
     1067
     1068  my $string = pb_Dump(list-of-Perl-data-structures);
    10651069
    10661070Turn Perl data into YAML. This function works very much like
    … …  
    10771081Dies on any error.
    10781082
    1079 =head2 Load
    1080 
    1081   my @data_structures = Load(string-containing-a-YAML-stream);
     1083=head2 pb_Load
     1084
     1085  my @data_structures = pb_Load(string-containing-a-YAML-stream);
    10821086
    10831087Turn YAML into Perl data. This is the opposite of Dump.
    … …  
    10911095socket.
    10921096
    1093   my $last_data_structure = Load(string-containing-a-YAML-stream);
     1097  my $last_data_structure = pb_Load(string-containing-a-YAML-stream);
    10941098
    10951099For consistency with YAML.pm, when Load is called in scalar context, it
    … …  
    11011105=head2 freeze() and thaw()
    11021106
    1103 Aliases to Dump() and Load() for L<Storable> fans. This will also allow
    1104 YAML::Tiny to be plugged directly into modules like POE.pm, that use the
     1107Aliases to pb_Dump() and pb_Load() for L<Storable> fans. This will also allow
     1108ProjectBuilder::YAML to be plugged directly into modules like POE.pm, that use the
    11051109freeze/thaw API for internal serialization.
    11061110
    1107 =head2 DumpFile(filepath, list)
     1111=head2 pb_DumpFile(filepath, list)
    11081112
    11091113Writes the YAML stream to a file with UTF-8 encoding instead of just
Note: See TracChangeset for help on using the changeset viewer.