Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instantiate Perl::Critic only once #11

Merged
merged 1 commit into from
Mar 26, 2018
Merged

Instantiate Perl::Critic only once #11

merged 1 commit into from
Mar 26, 2018

Conversation

holcapek
Copy link
Contributor

No description provided.

@petdance
Copy link
Member

Slick. I like it.


my $pc;
my $critic = sub {
my ( %args ) = @_;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be wise to singletonize the %args too, so that you don't get differently inited Critic instance after calling this with arguments different from the ones in the first call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dominik-Sauer I haven't exactly singletonize %args, but rather reset the possibly initialized P::C object with each call to import. I guess that solves the issue as well.

@@ -40,22 +47,16 @@ sub import {
if ( exists $args{-format} ) { $args{-verbose} = $args{-format}; }
%CRITIC_ARGS = %args;

# reset possibly lazy-initialized Perl::Critic
$CRITIC_OBJ = undef;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this commit, this might have happened:

Test::Perl::Critic->import( -profile => 'profile-A' );
critic_ok('source.pm');
# now $critic is initialized to P::C instance referring to profile-A

Test::Perl::Critic->import( -profile => 'profile-B' );
# here $critic hold the reference to P::C instance referring to profile-A

critic_ok('source.pm')
# the result might not be what you would expect

@@ -23,6 +23,13 @@ my $TEST = Test::Builder->new;
my $DIAG_INDENT = q{ };
my %CRITIC_ARGS = ();

my $CRITIC_OBJ = undef;
my $GET_CRITIC = sub {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use 'get' - my $BUILD_CRITIC

implementation:

    return $CRITIC_OBJ //= Perl::Critic->new( @_ )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, my fault, apparently it should work also for perl < 5.10
still, assign to %args is useless

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@branislav-zahradnik-gdc Ok, I'll change that.

@holcapek
Copy link
Contributor Author

holcapek commented Jan 4, 2018

I squashed couple of commits into one, since one without the others wouldn't make sense. The change is pretty small, anyway.

@petdance
Copy link
Member

petdance commented Jan 4, 2018

I'd like to get this merged, but the test fails under Travis. Can you please look into it?

@petdance
Copy link
Member

petdance commented Jan 4, 2018

And, are we sure there's no ill effects of reusing the singleton?

@holcapek
Copy link
Contributor Author

holcapek commented Jan 4, 2018

@petdance As for the test failing under Travis: it actually fails also on my local computer, but unfortunately, I didn't take it seriously. Moreover, it fails also with no changes to the upstream, as you can see at PR #13

I don't know what's wrong, I'll keep you posted if I find the cause.

@petdance
Copy link
Member

petdance commented Jan 4, 2018

Can I close this and let you create a new PR when you've got it going?

@holcapek
Copy link
Contributor Author

holcapek commented Jan 4, 2018

No problem, let's close it for now.

@holcapek holcapek closed this Jan 4, 2018
@holcapek holcapek mentioned this pull request Jan 5, 2018
@holcapek holcapek reopened this Jan 10, 2018
@holcapek
Copy link
Contributor Author

Hi @petdance , any chance this could be merged in provided the tests has been fixed previously? Thanks!

@pali
Copy link

pali commented Mar 26, 2018

@petdance: can you look at this change?

@petdance petdance merged commit 2a68fe9 into Perl-Critic:dev Mar 26, 2018
@petdance
Copy link
Member

Done. It's in the just-pushed-to-CPAN 1.04. Thanks for the nudge.

@holcapek
Copy link
Contributor Author

@petdance Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants