houseabsolute / p5-Test-Vars

Detects unused variables in unit tests
https://metacpan.org/pod/Test::Vars
Other
6 stars 10 forks source link

fails with unhelpful message when a sub and DBIx::Class relationship have the same name #38

Open abraxxa opened 6 years ago

abraxxa commented 6 years ago

This code

package NAC::Model::DBIC::Table::Line;

use Moose;
use namespace::autoclean;

extends 'NAC::Model::DBIC::Table::Parent::All';

...

__PACKAGE__->many_to_many( 'affecting_maintenances' => 'rel_affected_by_maintenances' => 'rel_maintenance' );

sub affecting_maintenances {...}

in a DBIx::Class::Result class leads to the test failing with:

not ok 63 - lib/NAC/Model/DBIC/Table/Line.pm
    #   Failed test 'lib/NAC/Model/DBIC/Table/Line.pm'
    #   at t/release-unused-vars.t line 20.
    # checking NAC::Model::DBIC::Table::Line in NAC/Model/DBIC/Table/Line.pm ...
    # looking into &NAC::Model::DBIC::Table::Line::affecting_maintenances
    # $sog is used once in &NAC::Model::DBIC::Table::Line::affecting_maintenances 
    # $self is used 1 times
    # $rs is used 2 times

Grepping my local Perl 5.28.0 library brings up the following usages of $sog:

[~/perl5/perlbrew/perls/28.0$ (master)]$ grep -R '$sog'
lib/site_perl/5.28.0/DBIx/Class/Relationship/ManyToMany.pm:      DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_WANTARRAY and my $sog = fail_on_internal_wantarray;
lib/site_perl/5.28.0/DBIx/Class/Relationship/Accessor.pm:      DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_WANTARRAY and my $sog = DBIx::Class::_Util::fail_on_internal_wantarray;
lib/site_perl/5.28.0/DBIx/Class/ResultSetColumn.pm:    DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_WANTARRAY and my $sog = fail_on_internal_wantarray;
lib/site_perl/5.28.0/DBIx/Class/ResultSet.pm:    DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_WANTARRAY and my $sog = fail_on_internal_wantarray;