]> diplodocus.org Git - flac-archive/commitdiff
tidy and test epg::flac::archive::tags::disc_tags
authorEric Gillespie <epg@pretzelnet.org>
Mon, 7 Mar 2022 00:56:44 +0000 (18:56 -0600)
committerEric Gillespie <epg@pretzelnet.org>
Mon, 7 Mar 2022 01:02:14 +0000 (19:02 -0600)
flac2mp3
t/disc_tags.t [new file with mode: 0644]
tags.pl

index b4126e2..d82e61d 100755 (executable)
--- a/flac2mp3
+++ b/flac2mp3
@@ -68,7 +68,7 @@ epg::flac::archive::tags->import(
 sub flac2mp3 {
     my $quoted_flac = quote(shift);
     my $tags = shift;
 sub flac2mp3 {
     my $quoted_flac = quote(shift);
     my $tags = shift;
-    my ($album, $artist, $date, $discnumber) = disc_tags($tags);
+    my ($artist, $album, $date, $discnumber) = disc_tags(%$tags);
 
         # TODO resurrect whole-disc FLAC?
         # Stupid hack: only a single-track file should have the
 
         # TODO resurrect whole-disc FLAC?
         # Stupid hack: only a single-track file should have the
diff --git a/t/disc_tags.t b/t/disc_tags.t
new file mode 100644 (file)
index 0000000..b37424e
--- /dev/null
@@ -0,0 +1,38 @@
+use v5.12;
+use warnings;
+
+use Test::Simple tests => 2;
+
+use Test::Differences;
+
+require './tags.pl';
+epg::flac::archive::tags->import('disc_tags');
+
+eq_or_diff
+    [disc_tags(
+         ARTIST => ['Fates Warning'],
+         ALBUM => ['The Spectre Within'],
+         DATE => [1985],
+     )],
+    [
+     'Fates Warning',
+     'The Spectre Within',
+     '1985',
+     [],
+    ],
+    'single disc';
+
+eq_or_diff
+    [disc_tags(
+         ARTIST => ['Depeche Mode'],
+         ALBUM => [101],
+         DATE => ['1989-03-14'],
+         DISCNUMBER => [2],
+     )],
+    [
+     'Depeche Mode',
+     '101',
+     '1989-03-14',
+     [2],
+    ],
+    'second disc';
diff --git a/tags.pl b/tags.pl
index 2df6458..71e6968 100644 (file)
--- a/tags.pl
+++ b/tags.pl
@@ -1,5 +1,15 @@
 package epg::flac::archive::tags;
 
 package epg::flac::archive::tags;
 
+=head1 NAME tags.pl
+
+subroutines for tag processing
+
+=head1 DESCRIPTION
+
+TODO
+
+=cut
+
 # POSIX.1-2017, Base Definitions, 3.282  Portable Filename Character Set says
 #   [A-Za-z0-9._-]
 # https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282
 # POSIX.1-2017, Base Definitions, 3.282  Portable Filename Character Set says
 #   [A-Za-z0-9._-]
 # https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282
@@ -115,37 +125,59 @@ sub one {
     $tag
 }
 
     $tag
 }
 
+=over
+
+=item B<disc_tags>
+
+Interpret the tags hash for a disc, returning:
+
+=over
+
+=item *
+Artist tag (exactly one required in the hash).
+
+=item *
+Album tag (exactly one required).
+
+=item *
+Date tag (zero or one required).
+
+=item *
+Disc number (zero or one required) as a reference to an array of size 0 or 1.
+
+=back
+=cut
 sub disc_tags {
 sub disc_tags {
-    my $album = shift;
+    my %tags = @_;
 
 
-    if (!defined($album->{ALBUM}) || @{$album->{ALBUM}} != 1) {
+    if (!defined($tags{ALBUM}) || @{$tags{ALBUM}} != 1) {
         die('exactly one ALBUM tag required')
     }
         die('exactly one ALBUM tag required')
     }
-    my $album_tag = $album->{ALBUM}->[0];
+    my $album_tag = $tags{ALBUM}->[0];
 
     # TODO ALBUMARTIST
 
     # TODO ALBUMARTIST
-    if (!defined($album->{ARTIST}) || @{$album->{ARTIST}} != 1) {
+    if (!defined($tags{ARTIST}) || @{$tags{ARTIST}} != 1) {
         die('exactly one ARTIST tag required')
     }
         die('exactly one ARTIST tag required')
     }
-    my $artist = $album->{ARTIST}->[0];
+    my $artist = $tags{ARTIST}->[0];
 
     my $date;
 
     my $date;
-    if (defined($album->{DATE})) {
-        if (@{$album->{DATE}} != 1) {
+    if (defined($tags{DATE})) {
+        if (@{$tags{DATE}} != 1) {
             die('one or zero DATE tags required')
         }
             die('one or zero DATE tags required')
         }
-        $date = $album->{DATE}->[0];
+        $date = $tags{DATE}->[0];
     }
 
     my @discnumber = ();
     }
 
     my @discnumber = ();
-    if (defined($album->{DISCNUMBER})) {
-        if (@{$album->{DISCNUMBER}} != 1) {
+    if (defined($tags{DISCNUMBER})) {
+        if (@{$tags{DISCNUMBER}} != 1) {
             die('one or zero DISCNUMBER tags required')
         }
             die('one or zero DISCNUMBER tags required')
         }
-        @discnumber = ($album->{DISCNUMBER}->[0]);
+        @discnumber = ($tags{DISCNUMBER}->[0]);
     }
 
     }
 
-    $album_tag, $artist, $date, \@discnumber
+    $artist, $album_tag, $date, \@discnumber
 }
 
 sub mangle_for_file_name {
 }
 
 sub mangle_for_file_name {
@@ -166,4 +198,8 @@ sub quote {
     "'$s'"
 }
 
     "'$s'"
 }
 
+=back
+
+=cut
+
 1;
 1;