Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issues with pbp identified on rt #72162

  • Loading branch information...
commit f85a39a7b3a41bbbcedf544bc4469ad66559ce1e 1 parent da7a46e
@riemann42 riemann42 authored
View
4 .gitignore
@@ -14,3 +14,7 @@ Makefile.old
*.tar.gz
cover_db
Debian_CPANTS.txt*
+lib.old
+tmp
+MYMETA.yml
+t/LWPCache
View
39 lib/Music/Tag.pm
@@ -70,7 +70,9 @@ sub new {
bless $self, $class;
$self->{_plugins} = [];
$self->options($options);
- $self->filename($filename);
+ if ($filename) {
+ $self->set_data('filename', $filename);
+ }
$self->{changed} = 0;
}
@@ -249,24 +251,27 @@ sub options { ## no critic (Subroutines::RequireArgUnpacking)
sub setfileinfo {
my $self = shift;
- if ( $self->filename ) {
- my $st = stat $self->filename;
- $self->mepoch( $st->mtime );
- $self->bytes( $st->size );
+ if ( $self->get_data('filename' )) {
+ my $st = stat $self->get_data('filename');
+ $self->set_data('mepochr', $st->mtime );
+ $self->set_data('bytes', $st->size );
return $st;
}
return;
}
+sub get_sha1 { goto &sha1; }
+
sub sha1 {
my $self = shift;
- if ( not( ( $self->filename ) && ( -e $self->filename ) ) ) {
+ my $filename = $self->get_data('filename');
+ if ( not( ( $filename ) && ( -e $filename ) ) ) {
return undef; ## no critic (Subroutines::ProhibitExplicitReturnUndef)
}
my $maxsize = $SHA1_SIZE;
my $in = IO::File->new();
- $in->open( $self->filename, '<' ) or die "Bad file: $self->filename\n";
- my $st = stat $self->filename;
+ $in->open( $filename, '<' ) or die "Bad file: $filename\n";
+ my $st = stat $filename;
my $sha1 = Digest::SHA1->new();
$sha1->add( pack( 'V', $st->size ) );
my $d;
@@ -321,6 +326,17 @@ sub set_picture {
return $self->picture($value);
}
+sub set_picture_filename {
+ my $self = shift;
+ my $value = shift;
+ return $self->picture_filename($value);
+}
+
+sub get_picture_filename {
+ my $self = shift;
+ return $self->picture_filename();
+}
+
sub picture_filename {
my $self = shift;
my $new = shift;
@@ -501,6 +517,7 @@ sub _add_to_namespace {
if ($PBP_METHODS) {
if ((not defined *{ $package . '::set_' . $attrname }) && ($writer)) { *{ $package . '::set_' . $attrname } = $writer; }
if ((not defined *{ $package . '::get_' . $attrname }) && ($reader)) { *{ $package . '::get_' . $attrname } = $reader; }
+ $METHODS{$attrname}->{writer} = $writer;
}
if ($TRADITIONAL_METHODS || $PBP_METHODS) {
if ((not defined *{ $package . '::has_' . $attrname }) && ($predicate)) { *{ $package . '::has_' . $attrname } = $predicate; }
@@ -863,12 +880,12 @@ sub _create_attributes {
$package->_make_accessor(
'albumartist' => {
- builder => sub { my $self = shift; return $self->artist() }
+ builder => sub { my $self = shift; return $self->get_data('artist') }
}
);
$package->_make_accessor(
'albumartist_sortname' => {
- builder => sub { my $self = shift; return $self->sortname() }
+ builder => sub { my $self = shift; return $self->get_data('sortname') }
}
);
$package->_make_list_accessor( 'albumtags' => {} );
@@ -1445,7 +1462,7 @@ global options. For example:
Sets the mtime and bytes attributes for you from filename. This may be
moved to the L<File|Music::Tag::File> plugin in the future.
-=item B<sha1()>
+=item B<sha1()> B<get_sha1()>
Returns a sha1 digest of the file size in little endian then the first 16K of
the music file. Should be fairly unique.
View
50 lib/Music/Tag/Test.pm
@@ -9,10 +9,16 @@ use Digest::SHA1;
use File::Copy;
use 5.006;
-@EXPORT = qw(create_tag read_tag random_write random_read random_write_num random_read_num random_write_date random_read_date filetest);
+@EXPORT = qw(create_tag read_tag random_write random_read random_write_num random_read_num random_write_date random_read_date filetest test_pbp);
my %values = ();
+my $PBP_METHODS = 0;
+
+sub test_pbp {
+ $PBP_METHODS = 1;
+}
+
sub create_tag {
my $filetest = shift;
my $tagoptions = shift;
@@ -35,7 +41,8 @@ sub read_tag {
SKIP: {
skip "$meth test skipped", 1 if (! $testoptions->{values_in}->{$meth});
$c++;
- cmp_ok($tag->$meth, 'eq', $testoptions->{values_in}->{$meth});
+ my $ameth = $PBP_METHODS ? 'get_' . $meth : $meth;
+ cmp_ok($tag->$ameth, 'eq', $testoptions->{values_in}->{$meth});
}
}
return $c;
@@ -49,7 +56,8 @@ sub random_write {
foreach my $meth (@{$testoptions->{random_write}}) {
my $val = "test" . $meth . int(rand(1000));
$values{$meth} = $val;
- ok($tag->$meth($val), 'auto write to ' . $meth);
+ my $wmeth = $PBP_METHODS ? 'set_' . $meth : $meth;
+ ok($tag->$wmeth($val), 'auto write to ' . $meth);
$c++;
}
return $c;
@@ -63,7 +71,8 @@ sub random_write_num {
foreach my $meth (@{$testoptions->{random_write_num}}) {
my $val = int(rand(10))+1;
$values{$meth} = $val;
- ok($tag->$meth($val), 'auto write to ' . $meth);
+ my $wmeth = $PBP_METHODS ? 'set_' . $meth : $meth;
+ ok($tag->$wmeth($val), 'auto write to ' . $meth);
$c++;
}
return $c;
@@ -77,7 +86,8 @@ sub random_write_date {
foreach my $meth (@{$testoptions->{random_write_date}}) {
my $val = int(rand(1_400_000_000)) + 399_999_999;
$values{$meth} = $val;
- ok($tag->$meth($val), 'auto write to '. $meth);
+ my $wmeth = $PBP_METHODS ? 'set_' . $meth : $meth;
+ ok($tag->$wmeth($val), 'auto write to '. $meth);
$c++;
}
return $c;
@@ -89,7 +99,8 @@ sub random_read {
return 0 if (! exists $testoptions->{random_write});
my $c = 0;
foreach my $meth (@{$testoptions->{random_write}}) {
- cmp_ok($tag->$meth, 'eq', $values{$meth}, 'auto read of ' . $meth);
+ my $ameth = $PBP_METHODS ? 'get_' . $meth : $meth;
+ cmp_ok($tag->$ameth, 'eq', $values{$meth}, 'auto read of ' . $meth);
$c++;
}
return $c;
@@ -101,7 +112,8 @@ sub random_read_num {
return 0 if (! exists $testoptions->{random_write_num});
my $c = 0;
foreach my $meth (@{$testoptions->{random_write_num}}) {
- cmp_ok($tag->$meth, '==', $values{$meth}, 'auto read of ' . $meth);
+ my $ameth = $PBP_METHODS ? 'get_' . $meth : $meth;
+ cmp_ok($tag->$ameth, '==', $values{$meth}, 'auto read of ' . $meth);
$c++;
}
return $c;
@@ -118,6 +130,10 @@ sub random_read_date {
my $meth_d = $meth;
$meth_d =~ s/epoch/date/;
$meth_d =~ s/_date//;
+ if ($PBP_METHODS) {
+ $meth_t = 'get_' . $meth_t;
+ $meth_d = 'get_' . $meth_d;
+ }
my @tm = gmtime($values{$meth});
cmp_ok(substr($tag->$meth_t,0,16), 'eq', substr(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $tm[5]+1900, $tm[4]+1, $tm[3], $tm[2], $tm[1], $tm[0]),0,16), 'auto read from '. $meth_t);
cmp_ok($tag->$meth_d, 'eq', sprintf('%04d-%02d-%02d', $tm[5]+1900, $tm[4]+1, $tm[3]), 'auto read from '. $meth_d);
@@ -131,11 +147,12 @@ sub read_picture {
my $testoptions = shift;
my $c = 0;
return 0 if (! $testoptions->{picture_read});
- ok($tag->picture_exists, 'Picture Exists');
+ ok($tag->has_picture, 'Picture Exists');
$c+=2;
if ($testoptions->{picture_sha1}) {
my $sha1 = Digest::SHA1->new();
- $sha1->add($tag->picture->{_Data});
+ my $rmeth = $PBP_METHODS ? 'get_picture' : 'picture';
+ $sha1->add($tag->$rmeth->{_Data});
cmp_ok($sha1->hexdigest, 'eq', $testoptions->{picture_sha1}, 'digest of picture matches during read');
$c++;
}
@@ -146,12 +163,13 @@ sub write_picture {
my $testoptions = shift;
my $c = 0;
return 0 if (! $testoptions->{picture_file});
- ok($tag->picture_filename($testoptions->{picture_file}), 'add picture');
- ok($tag->picture_exists, 'Picture Exists after write');
+ ok($tag->set_picture_filename($testoptions->{picture_file}), 'add picture');
+ ok($tag->has_picture, 'Picture Exists after write');
$c+=2;
if ($testoptions->{picture_sha1}) {
my $sha1 = Digest::SHA1->new();
- $sha1->add($tag->picture->{_Data});
+ my $rmeth = $PBP_METHODS ? 'get_picture' : 'picture';
+ $sha1->add($tag->$rmeth->{_Data});
cmp_ok($sha1->hexdigest, 'eq', $testoptions->{picture_sha1}, 'digest of picture matches after write');
$c++;
}
@@ -177,10 +195,10 @@ sub filetest {
read_tag($tag,$testoptions);
if ($testoptions->{picture_in}) {
- ok($tag->picture_exists, 'Picture should exists');
+ ok($tag->has_picture, 'Picture should exists');
}
else {
- ok(! $tag->picture_exists, 'Picture should not exist');
+ ok(! $tag->has_picture, 'Picture should not exist');
}
$c++;
@@ -255,6 +273,10 @@ Music::Tag::Test provides routines to test Music::Tag plugins
=over
+=item B<test_pbp>
+
+Use pbp methods for remaining tests.
+
=item B<filetest()>
Takes a hashref of options to perform multiple test on a file.
View
117 t/2-options-pbp.t
@@ -0,0 +1,117 @@
+#!/usr/bin/perl -w
+use strict;
+
+use Test::More tests => 171;
+use 5.006;
+
+BEGIN { use_ok('Music::Tag', pbp => 1) }
+
+my $tag = Music::Tag->new(
+ undef,
+ {artist => "Sarah Slean",
+ album => "Orphan Music",
+ title => "Mary",
+ comment => undef, # Should be ignored for now.
+ ANSIColor => 0,
+ quiet => 1,
+ locale => "ca"
+ },
+ "Option"
+ );
+
+ok($tag, 'Object created');
+ok($tag->get_tag, 'get_tag called');
+
+cmp_ok($tag->get_artist, 'eq', 'Sarah Slean', 'artist');
+cmp_ok($tag->get_album, 'eq', 'Orphan Music', 'album');
+cmp_ok($tag->get_albumartist, 'eq', 'Sarah Slean', 'albumartist');
+
+ok(!defined $tag->get_comment, 'comment should be undefined');
+
+ok($tag->set_encoded_by('Sarah'), 'Set encoded_by');
+cmp_ok($tag->get_encoded_by, 'eq', 'Sarah', 'Get encoded_by');
+$tag->set_albumtags('Canada,Female,Bible Reference');
+cmp_ok($tag->get_albumtags->[2], 'eq', 'Bible Reference', 'albumtags');
+$tag->set_artisttags(['Canada', 'Female']);
+cmp_ok($tag->get_artisttags->[1], 'eq', 'Female', 'artisttags');
+
+ok($tag->set_countrycode('CA'), 'Set Country Code');
+cmp_ok($tag->get_countrycode, 'eq', 'CA', 'Get Country Code');
+ok(length($tag->get_country) > 4, 'country from code');
+
+ok($tag->set_discnum('2/3'), 'Set discnum');
+cmp_ok($tag->get_disc, '==', 2, 'Get discnum');
+cmp_ok($tag->get_totaldiscs, '==', 3, 'Get totaldiscs');
+
+ok($tag->set_track(4), 'Set track');
+ok($tag->set_totaltracks(40), 'Set total tracks');
+cmp_ok($tag->get_tracknum, 'eq', '4/40', 'Get tracknum');
+
+ok($tag->set_ean('0825646392322'), 'Set ean');
+cmp_ok($tag->get_upc, 'eq', '825646392322', 'Get upc');
+
+ok($tag->set_releasetime('2006-10-31 1:01:02'), 'Set releasetime');
+cmp_ok($tag->get_releasedate, 'eq', '2006-10-31', 'releasedate');
+
+ok($tag->datamethods('testit'), 'add custom method');
+ok($tag->set_testit('blue'), 'write to custom method');
+cmp_ok($tag->get_testit, 'eq', 'blue', 'read custom method');
+
+foreach my $meth (
+ qw(album album_type albumartist albumartist_sortname albumid appleid artist artist_type artistid asin bitrate booklet codec comment compilation composer copyright disctitle encoded_by encoder genre ipod ipod_dbid ipod_location ipod_trackid label lyrics mb_albumid mb_artistid mb_trackid mip_puid originalartist path sortname title url user filetype mip_fingerprint)
+ ) {
+ my $val = "test" . $meth . int(rand(1000));
+ my ($wmeth,$rmeth) = ('set_'.$meth, 'get_'. $meth);
+ ok($tag->$wmeth($val), 'auto write to ' . $meth);
+ cmp_ok($tag->$rmeth, 'eq', $val, 'auto read from ' . $meth);
+}
+
+foreach my $meth (
+ qw( bytes disc duration frames framesize frequency gaplessdata playcount postgap pregap rating albumrating samplecount secs stereo tempo totaldiscs totaltracks )
+ ) {
+ my $val = int(rand(10))+1;
+ my ($wmeth,$rmeth) = ('set_'.$meth, 'get_'. $meth);
+ ok($tag->$wmeth($val), 'auto write to ' . $meth);
+ cmp_ok($tag->$rmeth, '==', $val, 'auto read from ' . $meth);
+}
+
+my %values = ();
+
+foreach my $meth (
+ qw(artist_end_epoch artist_start_epoch lastplayedepoch mepoch recordepoch releaseepoch)) {
+ my $val = int(rand(1_800_000_000));
+ $values{$meth} = $val;
+ my ($wmeth,$rmeth) = ('set_'.$meth, 'get_'. $meth);
+ ok($tag->$wmeth($val), 'auto write to '. $meth);
+ cmp_ok($tag->$rmeth, '==', $val, 'auto read from' . $meth);
+}
+
+foreach my $meth (
+ qw(artist_end_date artist_start_date lastplayeddate mdate recorddate releasedate)) {
+ my $me = $meth;
+ my $md = $meth;
+ $me =~ s/date/epoch/;
+ $md =~ s/_date//;
+ $md = 'get_' . $md;
+ my @tm = gmtime($values{$me});
+ cmp_ok($tag->$md, 'eq', sprintf('%04d-%02d-%02d', $tm[5]+1900, $tm[4]+1, $tm[3]), 'auto read from '. $md);
+}
+
+foreach my $meth (
+ qw(artist_end_time artist_start_time lastplayedtime mtime recordtime releasetime)) {
+ my $me = $meth;
+ $me =~ s/time/epoch/;
+ my @tm = gmtime($values{$me});
+ my $rmeth = 'get_'.$meth;
+ cmp_ok($tag->$rmeth, 'eq', sprintf('%04d-%02d-%02d %02d:%02d:%02d', $tm[5]+1900, $tm[4]+1, $tm[3], $tm[2], $tm[1], $tm[0]), 'auto read from '. $meth);
+}
+
+foreach my $meth (qw(recorddate releasedate)) {
+ my ($wmeth,$rmeth) = ('set_'.$meth, 'get_'. $meth);
+ ok($tag->$wmeth('2009-07-12'), 'auto write to ' . $meth);
+ cmp_ok($tag->$rmeth, 'eq', '2009-07-12', 'auto read from' . $meth);
+}
+
+ok(!$tag->setfileinfo, 'setfileinfo should fail');
+ok(!$tag->get_sha1, 'sha1 should fail');
+
Please sign in to comment.
Something went wrong with that request. Please try again.