| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package YAML::Merge::Simple; | ||||||||||
| 4 | { | ||||||||||
| 5 | 1 | $YAML::Merge::Simple::VERSION = '0.01_01'; | |||||||||
| 6 | } | ||||||||||
| 7 | 1 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Hash::Merge::Simple; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use YAML::XS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | # ABSTRACT: Recursively merge two or more YAMLs, simply | ||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use vars qw/ @ISA @EXPORT_OK /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | require Exporter; | |||||||||
| 15 | 1 | @ISA = qw/ Exporter /; | |||||||||
| 16 | 1 | @EXPORT_OK = qw/ merge merge_files /; | |||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | # This was stoled from Hash::Merge::Simple, which was inspired by Catalyst::Utils... thanks guys! | ||||||||||
| 20 | 3 | ▶ | sub merge_files { | ||||||||
|
Subroutine
merge_files: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 21 | 3 | ▶ | shift unless -f $_[0]; # Take care of the case we're called like YAML::Merge::Simple->merge_files(...) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 3 | my @hashes = map { YAML::XS::LoadFile $_ } @_; | |||||||||
| 23 | 3 | my $hash = Hash::Merge::Simple::merge(@hashes); | |||||||||
| 24 | 3 | return Dump $hash; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 1 | ▶ | sub merge { | ||||||||
|
Subroutine
merge: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 28 | 1 | ▶ | shift unless ref $_[0]; # Take care of the case we're called like YAML::Merge::Simple->merge(...) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 1 | my @hashes = map { YAML::XS::Load $_ } @_; | |||||||||
| 30 | 1 | my $hash = Hash::Merge::Simple::merge(@hashes); | |||||||||
| 31 | 1 | return Dump $hash; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 1 | 1; | |||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | =pod | ||||||||||
| 38 | |||||||||||
| 39 | =head1 NAME | ||||||||||
| 40 | |||||||||||
| 41 | YAML::Merge::Simple - Recursively merge two or more YAMLs, simply | ||||||||||
| 42 | |||||||||||
| 43 | =head1 VERSION | ||||||||||
| 44 | |||||||||||
| 45 | version 0.01_01 | ||||||||||
| 46 | |||||||||||
| 47 | =head1 SYNOPSIS | ||||||||||
| 48 | |||||||||||
| 49 | use YAML::Merge::Simple qw/ merge_files /; | ||||||||||
| 50 | |||||||||||
| 51 | # a: 1 | ||||||||||
| 52 | my $yaml1 = shift; | ||||||||||
| 53 | |||||||||||
| 54 | # a: 100 | ||||||||||
| 55 | # b: 2 | ||||||||||
| 56 | my $yaml2 = shift; | ||||||||||
| 57 | |||||||||||
| 58 | # Merge with righthand hash taking precedence | ||||||||||
| 59 | my $new_yaml = merge_files $yaml1,yaml2 | ||||||||||
| 60 | # $c (note: a: 100 has overridden a: 1) | ||||||||||
| 61 | # a: 100 | ||||||||||
| 62 | # b: 2 | ||||||||||
| 63 | |||||||||||
| 64 | =head1 DESCRIPTION | ||||||||||
| 65 | |||||||||||
| 66 | YAML::Merge::Simple will recursively merge two or more YAML files and return the result as a string with the content of a new YAML. | ||||||||||
| 67 | |||||||||||
| 68 | This is just a wrapper around Hash::Merge::Simple which uses YAML::XS to load the YAMLs into hashes, uses Hash::Merge::Simple to merge them and them uses YAML::XS again to dump the resulting hash back to YAML: | ||||||||||
| 69 | |||||||||||
| 70 | =head1 NAME | ||||||||||
| 71 | |||||||||||
| 72 | YAML::Merge::Simple - Recursively merge two or more YAMLs, simply | ||||||||||
| 73 | |||||||||||
| 74 | =head1 USAGE | ||||||||||
| 75 | |||||||||||
| 76 | =head2 Hash::Merge::Simple::merge_files( $file1, $file2, $file3, ..., $fileN ) | ||||||||||
| 77 | |||||||||||
| 78 | Merge $file1 through $fileN, with the nth-most (rightmost) YAML taking precedence. | ||||||||||
| 79 | |||||||||||
| 80 | Returns a string with the YAML content of the merge. | ||||||||||
| 81 | |||||||||||
| 82 | =head2 Hash::Merge::Simple::merge( $string1, $string2, $string3, ..., $stringN ) | ||||||||||
| 83 | |||||||||||
| 84 | Merge $string1 through $stringN, with the nth-most (rightmost) YAML taking precedence. | ||||||||||
| 85 | |||||||||||
| 86 | Returns a string with the YAML content of the merge. | ||||||||||
| 87 | |||||||||||
| 88 | =head1 SEE ALSO | ||||||||||
| 89 | |||||||||||
| 90 | L<Hash::Merge::Simple> | ||||||||||
| 91 | |||||||||||
| 92 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 93 | |||||||||||
| 94 | This code is almost entirely based on the current implementation of L<Hash::Merge::Simple>: | ||||||||||
| 95 | |||||||||||
| 96 | Robert Krimen C<robertkrimen@gmail.com> | ||||||||||
| 97 | |||||||||||
| 98 | =head1 AUTHOR | ||||||||||
| 99 | |||||||||||
| 100 | Andre Santos <andrefs@cpan.org> | ||||||||||
| 101 | |||||||||||
| 102 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 103 | |||||||||||
| 104 | This software is copyright (c) 2012 by Andre Santos. | ||||||||||
| 105 | |||||||||||
| 106 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 107 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 108 | |||||||||||
| 109 | =cut | ||||||||||
| 110 | |||||||||||
| 111 | |||||||||||
| 112 | __END__ | ||||||||||