diff --git a/cgi/CRMS.pm b/cgi/CRMS.pm index eaaf1921..708e572e 100755 --- a/cgi/CRMS.pm +++ b/cgi/CRMS.pm @@ -66,7 +66,7 @@ sub new return $self; } -our $VERSION = '8.5.24'; +our $VERSION = '8.5.25'; sub Version { return $VERSION; diff --git a/lib/CRMS/RightsPredictor.pm b/lib/CRMS/RightsPredictor.pm index ae4a00d0..2ad66812 100644 --- a/lib/CRMS/RightsPredictor.pm +++ b/lib/CRMS/RightsPredictor.pm @@ -35,7 +35,8 @@ use constant { # Thus, if last source copyright year >= 1996 then the work is GATT-eligible. GATT_RESTORATION_START => 1996, COMMONWEALTH_CROWN_COPYRIGHT_TERM => 50, - COMMONWEALTH_STANDARD_TERM => 70 + COMMONWEALTH_STANDARD_TERM => 70, + CANADA_CORPORATE_TERM => 75 }; # Sanity check on reviewer-supplied date @@ -69,11 +70,13 @@ sub new { sub last_source_copyright { my $self = shift; my $death_or_pub_date = shift || ''; # Reviewer-supplied + my $is_pub = shift; # Treat $death_or_pub_date as pub date for corporate authors my $is_crown = shift; # Crown copyright my $reference_year = shift || POSIX::strftime("%Y", localtime); # The "current" year # Initialize return struct my $prediction = { death_or_pub_date => $death_or_pub_date, + is_pub => $is_pub, is_crown => $is_crown, reference_year => $reference_year, desc => [], @@ -204,14 +207,18 @@ sub predict_last_source_copyright { return if $prediction->{error}; my $country = $self->{record}->country; my $predictor = $TERM_PREDICTORS->{$country}; - my $term = $predictor->($prediction->{death_or_pub_date}, $prediction->{is_crown}); + my $term = $predictor->( + $prediction->{death_or_pub_date}, + $prediction->{is_pub}, + $prediction->{is_crown} + ); $prediction->{last_source_copyright_year} = $prediction->{death_or_pub_date} + $term; push @{$prediction->{desc}}, "Last $country © $prediction->{last_source_copyright_year} ($prediction->{death_or_pub_date} + $term-year term)"; } sub australia_term { - my ($death_or_pub_date, $is_crown) = @_; + my ($death_or_pub_date, undef, $is_crown) = @_; return COMMONWEALTH_CROWN_COPYRIGHT_TERM if $is_crown; return 50 if $death_or_pub_date < 1955; @@ -219,15 +226,15 @@ sub australia_term { } sub canada_term { - my ($death_or_pub_date, $is_crown) = @_; + my ($death_or_pub_date, $is_pub, $is_crown) = @_; return COMMONWEALTH_CROWN_COPYRIGHT_TERM if $is_crown; return 50 if $death_or_pub_date < 1972; - return COMMONWEALTH_STANDARD_TERM; + return $is_pub ? CANADA_CORPORATE_TERM : COMMONWEALTH_STANDARD_TERM; } sub united_kingdom_term { - my ($death_or_pub_date, $is_crown) = @_; + my ($death_or_pub_date, undef, $is_crown) = @_; return ($is_crown) ? COMMONWEALTH_CROWN_COPYRIGHT_TERM : COMMONWEALTH_STANDARD_TERM; } diff --git a/t/lib/CRMS/RightsPredictor.t b/t/lib/CRMS/RightsPredictor.t index adf1e53e..52d5ca96 100644 --- a/t/lib/CRMS/RightsPredictor.t +++ b/t/lib/CRMS/RightsPredictor.t @@ -24,15 +24,23 @@ subtest 'RightsPredictor::last_source_copyright' => sub { my $record = FakeMetadata::fake_record_with_008_and_leader($f008); my $rp = CRMS::RightsPredictor->new(record => $record); my $res = $rp->last_source_copyright(2000); - is($res->{last_source_copyright_year}, 2070); + is($res->{last_source_copyright_year}, 2070, 'UK baseline 70-year term'); }; - subtest 'UK crown' => sub { + subtest 'UK corporate work' => sub { my $f008 = '850423s1940 uk a 000 0 eng d'; my $record = FakeMetadata::fake_record_with_008_and_leader($f008); my $rp = CRMS::RightsPredictor->new(record => $record); my $res = $rp->last_source_copyright(2000, 1); - is($res->{last_source_copyright_year}, 2050); + is($res->{last_source_copyright_year}, 2070), 'UK corporate/anonymous 70-year term'; + }; + + subtest 'UK crown' => sub { + my $f008 = '850423s1940 uk a 000 0 eng d'; + my $record = FakeMetadata::fake_record_with_008_and_leader($f008); + my $rp = CRMS::RightsPredictor->new(record => $record); + my $res = $rp->last_source_copyright(2000, 0, 1); + is($res->{last_source_copyright_year}, 2050, 'UK crown copyright 50-year term'); }; subtest 'Canada pre-1972' => sub { @@ -40,31 +48,63 @@ subtest 'RightsPredictor::last_source_copyright' => sub { my $record = FakeMetadata::fake_record_with_008_and_leader($f008); my $rp = CRMS::RightsPredictor->new(record => $record); my $res = $rp->last_source_copyright(1970); - is($res->{last_source_copyright_year}, 2020); + is($res->{last_source_copyright_year}, 2020, 'Canada has 50-year term when the effective date is prior to 1972'); }; - subtest 'Canada 1972' => sub { + subtest 'Canada 1972 author death date' => sub { my $f008 = '850423s1940 cn a 000 0 eng d'; my $record = FakeMetadata::fake_record_with_008_and_leader($f008); my $rp = CRMS::RightsPredictor->new(record => $record); my $res = $rp->last_source_copyright(1972); - is($res->{last_source_copyright_year}, 2042); + is($res->{last_source_copyright_year}, 2042, 'Canada has 70-year term for author death dates on or after 1972'); + }; + + subtest 'Canada 1972 corporate work' => sub { + my $f008 = '850423s1940 cn a 000 0 eng d'; + my $record = FakeMetadata::fake_record_with_008_and_leader($f008); + my $rp = CRMS::RightsPredictor->new(record => $record); + my $res = $rp->last_source_copyright(1972, 1); + is($res->{last_source_copyright_year}, 2047, 'Canada has 75-year term for corporate/anonymous works published on or after 1972'); }; - subtest 'Canada post-1972' => sub { + subtest 'Canada post-1972 author death date' => sub { my $f008 = '850423s1940 cn a 000 0 eng d'; my $record = FakeMetadata::fake_record_with_008_and_leader($f008); my $rp = CRMS::RightsPredictor->new(record => $record); my $res = $rp->last_source_copyright(2000); - is($res->{last_source_copyright_year}, 2070); + is($res->{last_source_copyright_year}, 2070, 'Canada has 70-year term for author death dates on or after 1972'); }; - subtest 'Canada crown' => sub { + subtest 'Canada post-1972 corporate work' => sub { my $f008 = '850423s1940 cn a 000 0 eng d'; my $record = FakeMetadata::fake_record_with_008_and_leader($f008); my $rp = CRMS::RightsPredictor->new(record => $record); my $res = $rp->last_source_copyright(2000, 1); - is($res->{last_source_copyright_year}, 2050); + is($res->{last_source_copyright_year}, 2075, 'Canada has 75-year term for corporate/anonymous works published on or after 1972'); + }; + + subtest 'Canada pre-1972 crown' => sub { + my $f008 = '850423s1940 cn a 000 0 eng d'; + my $record = FakeMetadata::fake_record_with_008_and_leader($f008); + my $rp = CRMS::RightsPredictor->new(record => $record); + my $res = $rp->last_source_copyright(1970, 0, 1); + is($res->{last_source_copyright_year}, 2020, 'Canada has 50-year term for crown copyright works regardless of effective date'); + }; + + subtest 'Canada 1972 crown' => sub { + my $f008 = '850423s1940 cn a 000 0 eng d'; + my $record = FakeMetadata::fake_record_with_008_and_leader($f008); + my $rp = CRMS::RightsPredictor->new(record => $record); + my $res = $rp->last_source_copyright(1972, 0, 1); + is($res->{last_source_copyright_year}, 2022, 'Canada has 50-year term for crown copyright works regardless of effective date'); + }; + + subtest 'Canada post-1972 crown' => sub { + my $f008 = '850423s1940 cn a 000 0 eng d'; + my $record = FakeMetadata::fake_record_with_008_and_leader($f008); + my $rp = CRMS::RightsPredictor->new(record => $record); + my $res = $rp->last_source_copyright(2000, 0, 1); + is($res->{last_source_copyright_year}, 2050, 'Canada has 50-year term for crown copyright works regardless of effective date'); }; subtest 'Australia pre-1955' => sub { @@ -72,7 +112,7 @@ subtest 'RightsPredictor::last_source_copyright' => sub { my $record = FakeMetadata::fake_record_with_008_and_leader($f008); my $rp = CRMS::RightsPredictor->new(record => $record); my $res = $rp->last_source_copyright(1950); - is($res->{last_source_copyright_year}, 2000); + is($res->{last_source_copyright_year}, 2000, 'Australia has 50-year term when the effective date is prior to 1955'); }; subtest 'Australia 1955' => sub { @@ -80,7 +120,7 @@ subtest 'RightsPredictor::last_source_copyright' => sub { my $record = FakeMetadata::fake_record_with_008_and_leader($f008); my $rp = CRMS::RightsPredictor->new(record => $record); my $res = $rp->last_source_copyright(1955); - is($res->{last_source_copyright_year}, 2025); + is($res->{last_source_copyright_year}, 2025, 'Australia has 70-year term when the effective date is on or after 1955'); }; subtest 'Australia post-1955' => sub { @@ -88,15 +128,31 @@ subtest 'RightsPredictor::last_source_copyright' => sub { my $record = FakeMetadata::fake_record_with_008_and_leader($f008); my $rp = CRMS::RightsPredictor->new(record => $record); my $res = $rp->last_source_copyright(2000); - is($res->{last_source_copyright_year}, 2070); + is($res->{last_source_copyright_year}, 2070, 'Australia has 70-year term when the effective date is on or after 1955'); }; - subtest 'Australia crown' => sub { + subtest 'Australia pre-1955 crown' => sub { my $f008 = '850423s1940 at a 000 0 eng d'; my $record = FakeMetadata::fake_record_with_008_and_leader($f008); my $rp = CRMS::RightsPredictor->new(record => $record); - my $res = $rp->last_source_copyright(2000, 1); - is($res->{last_source_copyright_year}, 2050); + my $res = $rp->last_source_copyright(1940, 0, 1); + is($res->{last_source_copyright_year}, 1990, 'Australia has 50-year term for crown copyright works regardless of effective date'); + }; + + subtest 'Australia 1955 crown' => sub { + my $f008 = '850423s1940 at a 000 0 eng d'; + my $record = FakeMetadata::fake_record_with_008_and_leader($f008); + my $rp = CRMS::RightsPredictor->new(record => $record); + my $res = $rp->last_source_copyright(1955, 0, 1); + is($res->{last_source_copyright_year}, 2005, 'Australia has 50-year term for crown copyright works regardless of effective date'); + }; + + subtest 'Australia post-1955 crown' => sub { + my $f008 = '850423s1940 at a 000 0 eng d'; + my $record = FakeMetadata::fake_record_with_008_and_leader($f008); + my $rp = CRMS::RightsPredictor->new(record => $record); + my $res = $rp->last_source_copyright(2000, 0, 1); + is($res->{last_source_copyright_year}, 2050, 'Australia has 50-year term for crown copyright works regardless of effective date'); }; subtest 'Unknown country' => sub { @@ -104,7 +160,7 @@ subtest 'RightsPredictor::last_source_copyright' => sub { my $record = FakeMetadata::fake_record_with_008_and_leader($f008); my $rp = CRMS::RightsPredictor->new(record => $record); my $res = $rp->last_source_copyright(2000); - ok(!defined $res->{last_source_copyright_year}); + ok(!defined $res->{last_source_copyright_year}, 'Last source copyright year cannot be defined for unknown country'); ok(join(', ', @{$res->{desc}}) =~ m/country/i); }; @@ -115,7 +171,7 @@ subtest 'RightsPredictor::last_source_copyright' => sub { my @bogus_years = (undef, 'abcd', '', 12345); foreach my $year (@bogus_years) { my $res = $rp->last_source_copyright($year); - ok(!defined $res->{last_source_copyright_year}); + ok(!defined $res->{last_source_copyright_year}, 'Last source copyright year cannot be defined for unknown country'); ok(join(', ', @{$res->{desc}}) =~ m/unsupported/i); } }; @@ -127,8 +183,8 @@ subtest 'RightsPredictor::last_source_copyright' => sub { my @ok_years = ('-1', '-0', '0000', 999999); foreach my $year (@ok_years) { my $res = $rp->last_source_copyright(2000); - ok(defined $res->{last_source_copyright_year}); - ok(join(', ', $res->{desc}) !~ m/unsupported/i); + ok(defined $res->{last_source_copyright_year}, "Last source copyright year is defined even if the input is $year"); + ok(join(', ', $res->{desc}) !~ m/unsupported/i, "No 'unsupported date format' error for $year"); } }; }; @@ -243,4 +299,3 @@ subtest 'RightsPredictor::rights' => sub { }; done_testing(); -