Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package perl-Sub-Override for openSUSE:Factory checked in at 2024-01-05 21:39:57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-Sub-Override (Old) and /work/SRC/openSUSE:Factory/.perl-Sub-Override.new.28375 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Sub-Override" Fri Jan 5 21:39:57 2024 rev:12 rq:1136812 version:0.100.0 Changes: -------- --- /work/SRC/openSUSE:Factory/perl-Sub-Override/perl-Sub-Override.changes 2013-06-06 12:22:37.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.perl-Sub-Override.new.28375/perl-Sub-Override.changes 2024-01-05 21:40:01.403230742 +0100 @@ -1,0 +2,6 @@ +Wed Dec 6 03:07:31 UTC 2023 - Tina Müller <timueller+p...@suse.de> + +- updated to 0.10 + see /usr/share/doc/packages/perl-Sub-Override/Changes + +------------------------------------------------------------------- Old: ---- Sub-Override-0.09.tar.gz New: ---- Sub-Override-0.10.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-Sub-Override.spec ++++++ --- /var/tmp/diff_new_pack.WM3LGN/_old 2024-01-05 21:40:02.103256339 +0100 +++ /var/tmp/diff_new_pack.WM3LGN/_new 2024-01-05 21:40:02.107256485 +0100 @@ -1,7 +1,7 @@ # # spec file for package perl-Sub-Override # -# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2024 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -12,39 +12,40 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# Please submit bugfixes or comments via https://bugs.opensuse.org/ # +%define cpan_name Sub-Override Name: perl-Sub-Override -Version: 0.09 +Version: 0.100.0 Release: 0 -%define cpan_name Sub-Override +%define cpan_version 0.10 +License: Artistic-1.0 OR GPL-1.0-or-later Summary: Perl extension for easily overriding subroutines -License: GPL-1.0+ or Artistic-1.0 -Group: Development/Libraries/Perl -Url: http://search.cpan.org/dist/Sub-Override/ -Source: http://www.cpan.org/authors/id/O/OV/OVID/%{cpan_name}-%{version}.tar.gz +URL: https://metacpan.org/release/%{cpan_name} +Source0: https://cpan.metacpan.org/authors/id/O/OV/OVID/%{cpan_name}-%{cpan_version}.tar.gz BuildArch: noarch -BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: perl BuildRequires: perl-macros BuildRequires: perl(Test::Fatal) >= 0.010 Requires: perl(Test::Fatal) >= 0.010 +Provides: perl(Sub::Override) = %{version} +%define __perllib_provides /bin/true %{perl_requires} %description Perl extension for easily overriding subroutines %prep -%setup -q -n %{cpan_name}-%{version} +%autosetup -n %{cpan_name}-%{cpan_version} %build -%{__perl} Makefile.PL INSTALLDIRS=vendor -%{__make} %{?_smp_mflags} +perl Makefile.PL INSTALLDIRS=vendor +%make_build %check -%{__make} test +make test %install %perl_make_install @@ -52,6 +53,5 @@ %perl_gen_filelist %files -f %{name}.files -%defattr(-,root,root,755) %doc Changes README README.md ++++++ Sub-Override-0.09.tar.gz -> Sub-Override-0.10.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Sub-Override-0.09/Changes new/Sub-Override-0.10/Changes --- old/Sub-Override-0.09/Changes 2013-01-16 19:57:01.000000000 +0100 +++ new/Sub-Override-0.10/Changes 2023-12-05 15:36:04.000000000 +0100 @@ -1,4 +1,5 @@ -Revision history for Perl extension Sub::Override. +0.10 Wed Nov 22 2023 + Add a 'wrap' routine that allows you to call the original sub. 0.09 Wed Jan 16 2013 Switch from Test::Exception to Test::Fatal. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Sub-Override-0.09/META.json new/Sub-Override-0.10/META.json --- old/Sub-Override-0.09/META.json 2013-01-16 20:01:30.000000000 +0100 +++ new/Sub-Override-0.10/META.json 2023-12-05 15:36:31.000000000 +0100 @@ -4,13 +4,13 @@ "Curtis Poe <o...@cpan.org>" ], "dynamic_config" : 1, - "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120630", + "generated_by" : "ExtUtils::MakeMaker version 7.64, CPAN::Meta::Converter version 2.150010", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", - "version" : "2" + "version" : 2 }, "name" : "Sub-Override", "no_index" : { @@ -43,5 +43,6 @@ "url" : "https://github.com/Ovid/sub-override" } }, - "version" : "0.09" + "version" : "0.10", + "x_serialization_backend" : "JSON::PP version 4.09" } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Sub-Override-0.09/META.yml new/Sub-Override-0.10/META.yml --- old/Sub-Override-0.09/META.yml 2013-01-16 20:01:30.000000000 +0100 +++ new/Sub-Override-0.10/META.yml 2023-12-05 15:36:31.000000000 +0100 @@ -3,23 +3,24 @@ author: - 'Curtis Poe <o...@cpan.org>' build_requires: - ExtUtils::MakeMaker: 0 + ExtUtils::MakeMaker: '0' configure_requires: - ExtUtils::MakeMaker: 0 + ExtUtils::MakeMaker: '0' dynamic_config: 1 -generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120630' +generated_by: 'ExtUtils::MakeMaker version 7.64, CPAN::Meta::Converter version 2.150010' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html - version: 1.4 + version: '1.4' name: Sub-Override no_index: directory: - t - inc requires: - Test::Fatal: 0.010 - Test::More: 0.47 + Test::Fatal: '0.010' + Test::More: '0.47' resources: repository: https://github.com/Ovid/sub-override -version: 0.09 +version: '0.10' +x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Sub-Override-0.09/README.md new/Sub-Override-0.10/README.md --- old/Sub-Override-0.09/README.md 2013-01-16 19:55:34.000000000 +0100 +++ new/Sub-Override-0.10/README.md 2023-12-05 15:36:04.000000000 +0100 @@ -4,7 +4,7 @@ # VERSION -0.09 +0.10 # SYNOPSIS @@ -23,7 +23,7 @@ ## The Problem Sometimes subroutines need to be overridden. In fact, your author does this -constantly for tests. Particularly when testing, using a Mock Object can be +frequently for tests. Particularly when testing, using a Mock Object can be overkill when all you want to do is override one tiny, little function. Overriding a subroutine is often done with syntax similar to the following. @@ -42,7 +42,7 @@ } In the above example, not only have we probably misspelled the subroutine name, -but even if their had been a subroutine with that name, we haven't overridden +but even if there had been a subroutine with that name, we haven't overridden it. These two bugs can be subtle to detect. Further, if we're attempting to localize the effect by placing this code in a @@ -89,10 +89,26 @@ $override->replace('Some::thing', sub { 1 }); is($object->foo, 'puppies', 'puppies are returned if Some::thing is true'); +## Wrapping a subroutine + +There may be times when you want to 'conditionally' replace a subroutine - for +example, to override the original subroutine only if certain args are passed. +For this you can specify 'wrap' instead of 'replace'. Wrap is identical to +replace, except the original subroutine is passed as the first arg to your +new subroutine. You can call the original sub via 'shift->(@\_)': + + $override->wrap('Some::sub', + sub { + my ($old_sub, @args) = @_; + return 1 if $args[0]; + return $old_sub->(@args); + } + ); + ## Restoring subroutines If the object falls out of scope, the original subs are restored. However, if -you need to restore a subroutine early, just use the restore method: +you need to restore a subroutine early, just use the `restore()` method: my $override = Sub::Override->new('Some::sub', sub {'new data'}); # do stuff @@ -105,7 +121,7 @@ # do stuff } -If you have override more than one subroutine with an override object, you +If you have overridden more than one subroutine with an override object, you will have to explicitly name the subroutine you wish to restore: $override->restore('This::sub'); @@ -134,7 +150,7 @@ my $sub = Sub::Override->new; my $sub = Sub::Override->new($sub_name, $sub_ref); -Creates a new `Sub::Override` instance. Optionally, you may override a +Creates a new `Sub::Override` instance. Optionally, you may override a subroutine while creating a new object. ## replace @@ -147,7 +163,7 @@ $sub->replace($sub_name, $sub_body) ->replace($another_sub, $another_body); -This method will `croak` is the subroutine to be replaced does not exist. +This method will `croak` if the subroutine to be replaced does not exist. ## override @@ -167,26 +183,47 @@ None by default. +# CAVEATS + +If you need to override the same sub several times do not create a new +`Sub::Override` object, but instead always reuse the existing one and call +`replace` on it. Creating a new object to override the same sub will result +in weird behavior. + + # Do not do this! + my $sub_first = Sub::Override->new( 'Foo:bar' => sub { 'first' } ); + my $sub_second = Sub::Override->new( 'Foo::bar' => sub { 'second' } ); + + # Do not do this either! + my $sub = Sub::Override->new( 'Foo::bar' => sub { 'first' } ); + $sub = Sub::Override->new( 'Foo::bar' => sub { 'second' } ); + + +Both of those usages could result in of your subs being lost, depending +on the order in which you restore them. + +Instead, call `replace` on the existing `$sub`. + + my $sub = Sub::Override->new( 'Foo::bar' => sub { 'first' } ); + $sub->replace( 'Foo::bar' => sub { 'second' } ); + # BUGS Probably. Tell me about 'em. # SEE ALSO -- Hook::LexWrap -- can also override subs, but with different capabilities -- Test::MockObject -- use this if you need to alter an entire class +- [Hook::LexWrap](https://metacpan.org/pod/Hook%3A%3ALexWrap) -- can also override subs, but with different capabilities +- [Test::MockObject](https://metacpan.org/pod/Test%3A%3AMockObject) -- use this if you need to alter an entire class # AUTHOR Curtis "Ovid" Poe, `<ovid [at] cpan [dot] org>` -Reverse the name to email me. - # COPYRIGHT AND LICENSE -Copyright (C) 2004-2005 by Curtis "Ovid" Poe +Copyright (C) 2004-2013 by Curtis "Ovid" Poe This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available. - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Sub-Override-0.09/lib/Sub/Override.pm new/Sub-Override-0.10/lib/Sub/Override.pm --- old/Sub-Override-0.09/lib/Sub/Override.pm 2013-01-16 19:48:08.000000000 +0100 +++ new/Sub-Override-0.10/lib/Sub/Override.pm 2023-12-05 15:36:04.000000000 +0100 @@ -3,7 +3,7 @@ use strict; use warnings; -our $VERSION = '0.09'; +our $VERSION = '0.10'; my $_croak = sub { local *__ANON__ = '__ANON__croak'; @@ -73,6 +73,19 @@ return $self; } +sub wrap { + my ( $self, $sub_to_replace, $new_sub ) = @_; + $sub_to_replace = $self->$_normalize_sub_name($sub_to_replace); + $self->$_validate_code_slot($sub_to_replace)->$_validate_sub_ref($new_sub); + { + no strict 'refs'; + $self->{$sub_to_replace} ||= *$sub_to_replace{CODE}; + no warnings 'redefine'; + *$sub_to_replace = sub { $new_sub->( $self->{$sub_to_replace}, @_ ) }; + } + return $self; +} + sub restore { my ( $self, $name_of_sub ) = @_; $name_of_sub = $self->$_normalize_sub_name($name_of_sub); @@ -110,7 +123,7 @@ =head1 VERSION -0.09 +0.10 =head1 SYNOPSIS @@ -129,7 +142,7 @@ =head2 The Problem Sometimes subroutines need to be overridden. In fact, your author does this -constantly for tests. Particularly when testing, using a Mock Object can be +frequently for tests. Particularly when testing, using a Mock Object can be overkill when all you want to do is override one tiny, little function. Overriding a subroutine is often done with syntax similar to the following. @@ -148,7 +161,7 @@ } In the above example, not only have we probably misspelled the subroutine name, -but even if their had been a subroutine with that name, we haven't overridden +but even if there had been a subroutine with that name, we haven't overridden it. These two bugs can be subtle to detect. Further, if we're attempting to localize the effect by placing this code in a @@ -195,10 +208,26 @@ $override->replace('Some::thing', sub { 1 }); is($object->foo, 'puppies', 'puppies are returned if Some::thing is true'); +=head2 Wrapping a subroutine + +There may be times when you want to 'conditionally' replace a subroutine - for +example, to override the original subroutine only if certain args are passed. +For this you can specify 'wrap' instead of 'replace'. Wrap is identical to +replace, except the original subroutine is passed as the first arg to your +new subroutine. You can call the original sub via 'shift->(@_)': + + $override->wrap('Some::sub', + sub { + my ($old_sub, @args) = @_; + return 1 if $args[0]; + return $old_sub->(@args); + } + ); + =head2 Restoring subroutines If the object falls out of scope, the original subs are restored. However, if -you need to restore a subroutine early, just use the restore method: +you need to restore a subroutine early, just use the C<restore()> method: my $override = Sub::Override->new('Some::sub', sub {'new data'}); # do stuff @@ -211,7 +240,7 @@ # do stuff } -If you have override more than one subroutine with an override object, you +If you have overridden more than one subroutine with an override object, you will have to explicitly name the subroutine you wish to restore: $override->restore('This::sub'); @@ -240,7 +269,7 @@ my $sub = Sub::Override->new; my $sub = Sub::Override->new($sub_name, $sub_ref); -Creates a new C<Sub::Override> instance. Optionally, you may override a +Creates a new C<Sub::Override> instance. Optionally, you may override a subroutine while creating a new object. =head2 replace @@ -253,7 +282,7 @@ $sub->replace($sub_name, $sub_body) ->replace($another_sub, $another_body); -This method will C<croak> is the subroutine to be replaced does not exist. +This method will C<croak> if the subroutine to be replaced does not exist. =head2 override @@ -277,6 +306,29 @@ None by default. +=head1 CAVEATS + +If you need to override the same sub several times do not create a new +C<Sub::Override> object, but instead always reuse the existing one and call +C<replace> on it. Creating a new object to override the same sub will result +in weird behavior. + + # Do not do this! + my $sub_first = Sub::Override->new( 'Foo:bar' => sub { 'first' } ); + my $sub_second = Sub::Override->new( 'Foo::bar' => sub { 'second' } ); + + # Do not do this either! + my $sub = Sub::Override->new( 'Foo::bar' => sub { 'first' } ); + $sub = Sub::Override->new( 'Foo::bar' => sub { 'second' } ); + +Both of those usages could result in of your subs being lost, depending +on the order in which you restore them. + +Instead, call C<replace> on the existing C<$sub>. + + my $sub = Sub::Override->new( 'Foo::bar' => sub { 'first' } ); + $sub->replace( 'Foo::bar' => sub { 'second' } ); + =head1 BUGS Probably. Tell me about 'em. @@ -286,10 +338,10 @@ =over 4 =item * -Hook::LexWrap -- can also override subs, but with different capabilities +L<Hook::LexWrap> -- can also override subs, but with different capabilities =item * -Test::MockObject -- use this if you need to alter an entire class +L<Test::MockObject> -- use this if you need to alter an entire class =back @@ -297,15 +349,12 @@ Curtis "Ovid" Poe, C<< <ovid [at] cpan [dot] org> >> -Reverse the name to email me. - =head1 COPYRIGHT AND LICENSE -Copyright (C) 2004-2005 by Curtis "Ovid" Poe +Copyright (C) 2004-2013 by Curtis "Ovid" Poe This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available. - =cut diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Sub-Override-0.09/t/override.t new/Sub-Override-0.10/t/override.t --- old/Sub-Override-0.09/t/override.t 2013-01-16 19:54:23.000000000 +0100 +++ new/Sub-Override-0.10/t/override.t 2023-12-05 15:36:04.000000000 +0100 @@ -2,7 +2,7 @@ use strict; #use Test::More 'no_plan'; -use Test::More tests => 28; +use Test::More tests => 33; use Test::Fatal; my $CLASS; @@ -122,7 +122,7 @@ { - package Temp; + package TempReplace; sub foo {23} sub bar {42} @@ -133,6 +133,28 @@ $override->restore('foo'); main::is( foo(), 23, '... and we should be able to restore said sub' ); - $override->restore('Temp::bar'); + $override->restore('TempReplace::bar'); main::is( bar(), 42, '... even if we use a full qualified sub name' ); } + +can_ok( $override, 'wrap' ); + +{ + + package TempWrap; + sub foo {23} + + my $override = $CLASS->new; + + main::ok( $override->wrap( 'foo', + sub { + my ($orig, @args) = @_; + return $args[0] ? 24 : $orig->(); + } + ), '... and we should be able to successfully wrap a subroutine' ); + main::is( foo(), 23, '... and wrapped sub foo conditionally returns original value' ); + main::is( foo(1), 24, '... and wrapped sub foo conditionally returns override value' ); + + $override->restore('foo'); + main::is( foo(1), 23, '... and we can restore a wrapped subroutine' ); +}