| 1 | package YAML::Diff::Command; | ||
| 2 | 1 | ▶ | use Mo; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 3 | |||
| 4 | has args => (); | ||
| 5 | |||
| 6 | use YAML::XS; | ||
| 7 | use IO::All; | ||
| 8 | |||
| 9 | sub run { | ||
| 10 | my ($self) = @_; | ||
| 11 | |||
| 12 | my $args = $self->args; | ||
| 13 | @$args == 2 or die 'Command requires 2 YAML file paths'; | ||
| 14 | |||
| 15 | my ($file1, $file2) = @$args; | ||
| 16 | |||
| 17 | my $yaml1 = YAML::XS::Dump(YAML::XS::LoadFile($file1)); | ||
| 18 | my $yaml2 = YAML::XS::Dump(YAML::XS::LoadFile($file2)); | ||
| 19 | |||
| 20 | (my $tmp1 = $file1) =~ s!.*/!!; | ||
| 21 | (my $tmp2 = $file2) =~ s!.*/!!; | ||
| 22 | $tmp1 = "/tmp/$tmp1"; | ||
| 23 | $tmp2 = "/tmp/$tmp2"; | ||
| 24 | |||
| 25 | if ($yaml1 eq $yaml2) { | ||
| 26 | print "Matched\n"; | ||
| 27 | } | ||
| 28 | else { | ||
| 29 | io($tmp1)->print($yaml1); | ||
| 30 | io($tmp2)->print($yaml2); | ||
| 31 | system "diff -u $tmp1 $tmp2"; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | 1; | ||