Perl-Critic-TooMuchCode

 view release on metacpan or  search on metacpan

lib/Perl/Critic/Policy/TooMuchCode/ProhibitUnusedInclude.pm  view on Meta::CPAN

        'Data::NestedParams'           => [qw(expand_nested_params collapse_nested_params)],
        'Data::UUID'                   => [qw(NameSpace_DNS NameSpace_OID NameSpace_URL NameSpace_X500)],
        'Data::Validate::Domain'       => [qw(is_domain is_hostname is_domain_label)],
        'Data::Validate::IP'           => [qw(is_ip is_ipv4 is_ipv6 is_innet_ipv4 is_multicast_ipv4 is_testnet_ipv4 is_anycast_ipv4 is_loopback_ipv4 is_private_ipv4 is_unroutable_ipv4 is_linklocal_ipv4 is_public_ipv4 is_loopback_ipv6 is_orchid_ipv6 i...
        'Data::Walk'                   => [qw(walk walkdepth)],
        'Devel::CheckCompiler'         => [qw(check_c99 check_c99_or_exit check_compile)],
        'Devel::CheckLib'              => [qw(assert_lib check_lib_or_exit check_lib)],
        'Devel::GlobalDestruction'     => [qw(in_global_destruction)],
        'Dist::CheckConflicts'         => [qw(conflicts check_conflicts calculate_conflicts dist)],
        'Email::MIME::ContentType'     => [qw(parse_content_type parse_content_disposition)],
        'Encode'                       => [qw(decode decode_utf8 encode encode_utf8 str2bytes bytes2str encodings find_encoding find_mime_encoding clone_encoding)],
        'Eval::Closure'                => [qw(eval_closure)],
        'ExtUtils::MakeMaker'          => [qw(WriteMakefile prompt os_unsupported)],
        'File::HomeDir'                => [qw(home)],
        'File::Listing'                => [qw(parse_dir)],
        'File::Path'                   => [qw(mkpath rmtree)],
        'File::ShareDir::Install'      => [qw(install_share delete_share)],
        'File::Which'                  => [qw(which)],
        'File::Zglob'                  => [qw(zglob)],
        'File::pushd'                  => [qw(pushd tempd)],
        'Graphics::ColorUtils'         => [qw(rgb2yiq yiq2rgb rgb2cmy cmy2rgb rgb2hls hls2rgb rgb2hsv hsv2rgb)],
        'HTML::Escape'                 => [qw(escape_html)],
        'HTTP::Date'                   => [qw(time2str str2time)],
        'HTTP::Negotiate'              => [qw(choose)],
        'IO::All'                      => [qw(io)],
        'IO::HTML'                     => [qw(html_file)],
        'IO::Socket::SSL'              => [qw(SSL_WANT_READ SSL_WANT_WRITE SSL_VERIFY_NONE SSL_VERIFY_PEER SSL_VERIFY_FAIL_IF_NO_PEER_CERT SSL_VERIFY_CLIENT_ONCE SSL_OCSP_NO_STAPLE SSL_OCSP_TRY_STAPLE SSL_OCSP_MUST_STAPLE SSL_OCSP_FAIL_HARD SSL_OCSP_...
        'IPC::Run3'                    => [qw(run3)],
        'JSON'                         => [qw(from_json to_json jsonToObj objToJson encode_json decode_json)],
        'JSON::MaybeXS'                => [qw(encode_json decode_json JSON)],
        'JSON::PP'                     => [qw(encode_json decode_json from_json to_json)],
        'JSON::Types'                  => [qw(number string bool)],
        'JSON::XS'                     => [qw(encode_json decode_json)],
        'LWP::MediaTypes'              => [qw(guess_media_type media_suffix)],
        'Lingua::JA::Regular::Unicode' => [qw(hiragana2katakana alnum_z2h alnum_h2z space_z2h katakana2hiragana katakana_h2z katakana_z2h space_h2z)],
        'Locale::Currency::Format'     => [qw(currency_format currency_name currency_set currency_symbol decimal_precision decimal_separator thousands_separator FMT_NOZEROS FMT_STANDARD FMT_COMMON FMT_SYMBOL FMT_HTML FMT_NAME SYM_UTF SYM_HTML)],
        'Log::Minimal'                 => [qw(critf critff warnf warnff infof infoff debugf debugff croakf croakff ddf)],
        'MIME::Charset'                => [qw(body_encoding canonical_charset header_encoding output_charset body_encode encoded_header_len header_encode)],
        'Math::Round'                  => [qw(round nearest)],
        'Module::Build::Tiny'          => [qw(Build Build_PL)],
        'Module::Find'                 => [qw(findsubmod findallmod usesub useall setmoduledirs)],
        'Module::Functions'            => [qw(get_public_functions)],
        'Module::Spy'                  => [qw(spy_on)],
        'PLON'                         => [qw(encode_plon decode_pson)],
        'Path::Class'                  => [qw(file dir)],
        'Path::Tiny'                   => [qw(path)],
        'Proc::Wait3'                  => [qw(wait3)],
        'Readonly'                     => [qw(Readonly)],
        'SQL::QueryMaker'              => [qw(sql_op sql_raw sql_and sql_or sql_in sql_not_in sql_ne sql_not sql_like sql_is_not_null sql_is_null sql_ge sql_gt sql_eq sql_lt sql_le sql_between sql_not_between)],
        'Smart::Args'                  => [qw(args args_pos)],
        'Socket'                       => [qw(PF_802 PF_AAL PF_APPLETALK PF_CCITT PF_CHAOS PF_CTF PF_DATAKIT PF_DECnet PF_DLI PF_ECMA PF_GOSIP PF_HYLINK PF_IMPLINK PF_INET PF_INET6 PF_ISO PF_KEY PF_LAST PF_LAT PF_LINK PF_MAX PF_NBS PF_NIT PF_NS PF_OS...
        'String::Format'               => [qw(stringf)],
        'String::ShellQuote'           => [qw(shell_quote shell_quote_best_effort shell_comment_quote)],
        'Sub::Name'                    => [qw(subname)],
        'Sub::Quote'                   => [qw(quote_sub unquote_sub quoted_from_sub qsub)],
        'Sub::Retry'                   => [qw(retry)],
        'Teng::Plugin::TextTable'      => [qw(draw_text_table)],
        'Test2::V0'                    => [qw(ok pass fail diag note todo skip plan skip_all done_testing bail_out intercept context gen_event def do_def cmp_ok warns warning warnings no_warnings subtest can_ok isa_ok DOES_ok set_encoding imported_ok...
        'Test::BinaryData'             => [qw(is_binary)],
        'Test::Deep'                   => [qw(Isa blessed obj_isa all any array array_each arrayelementsonly arraylength arraylengthonly bag bool cmp_bag cmp_deeply cmp_methods cmp_set code eq_deeply hash hash_each hashkeys hashkeysonly ignore isa li...
        'Test::Differences'            => [qw(eq_or_diff eq_or_diff_text eq_or_diff_data unified_diff context_diff oldstyle_diff table_diff)],
        'Test::Exception'              => [qw(dies_ok lives_ok throws_ok lives_and)],
        'Test::Fatal'                  => [qw(exception)],
        'Test::Kantan'                 => [qw(Feature Scenario Given When Then subtest done_testing setup teardown describe context it before_each after_each expect ok diag ignore spy_on skip_all)],
        'Test::LongString'             => [qw(is_string is_string_nows like_string unlike_string contains_string lacks_string)],
        'Test::Mock::Guard'            => [qw(mock_guard)],
        'Test::More'                   => [qw(ok use_ok require_ok is isnt like unlike is_deeply cmp_ok skip todo todo_skip pass fail eq_array eq_hash eq_set plan done_testing can_ok isa_ok new_ok diag note explain subtest BAIL_OUT)],
        'Test::Object'                 => [qw(object_ok)],
        'Test::Output'                 => [qw(output_like stderr_from output_isnt stderr_is stdout_unlike combined_isnt output_is combined_is stdout_is stderr_isnt stdout_like combined_unlike stderr_unlike output_from combined_from stdout_isnt output...
        'Test::Simple'                 => [qw(ok)],
        'Test::Spec'                   => [qw(runtests describe xdescribe context xcontext it xit they xthey before after around yield spec_helper share shared_examples_for it_should_behave_like)],
        'Test::Stub'                   => [qw(stub make_stub)],
        'Test::SubCalls'               => [qw(sub_track sub_calls sub_reset sub_reset_all)],
        'Test::TempDir::Tiny'          => [qw(tempdir in_tempdir)],
        'Test::TCP'                    => [qw(empty_port test_tcp wait_port)],
        'Test::Warn'                   => [qw(warning_is warnings_are warning_like warnings_like warnings_exist)],
        'Text::Diff'                   => [qw(diff)],
        'Time::Piece'                  => [qw(localtime gmtime)],
        'Try::Tiny'                    => [qw(try catch finally)],
        'URI::Find'                    => [qw(find_uris)],
        'URL::Builder'                 => [qw(build_url build_url_utf8)],
        'UUID::Tiny'                   => [qw(UUID_NIL UUID_NS_DNS UUID_NS_URL UUID_NS_OID UUID_NS_X500 UUID_V1 UUID_V3 UUID_V4 UUID_V5 UUID_SHA1_AVAIL create_UUID create_UUID_as_string is_UUID_string UUID_to_string string_to_UUID version_of_UUID tim...
        'Want'                         => [qw(want rreturn lnoreturn)],
        'XML::Simple'                  => [qw(XMLin XMLout)],
        'YAML'                         => [qw(Dump Load)],
    }
};

sub violates {
    my ( $self, $elem, $doc ) = @_;

    my @includes = grep {
        my $mod = $_->module;
        !$_->pragma && $mod && (! $self->{_ignore}{$mod})
    } @{ $doc->find('PPI::Statement::Include') ||[] };

    return () unless @includes;

    return () if grep { $_->module eq 'Module::Functions' } @includes;

    my %uses;
    $self->gather_uses_pragmatists(\@includes, $doc, \%uses);
    $self->gather_uses_try_family(\@includes, $doc, \%uses);
    $self->gather_uses_generic(\@includes, $doc, \%uses);

    return map {
        $self->violation(
            "Unused include: " . $_->module,
            "A module is `use`-ed but not really consumed in other places in the code",
            $_
        )
    } grep {
        my $mod = $_->module;
        (! $uses{refaddr($_)}) && (TRY_FAMILY->{$mod} || DEFAULT_EXPORT->{$mod} || USE_BY_MODULE_NAME->{$mod})
    } @includes;
}

sub gather_uses_pragmatists {
    my ( $self, $includes, $doc, $uses ) = @_;
    for (grep { PRAGMATIST->{$_->module} } @$includes) {
        my $r = refaddr($_);



( run in 1.535 second using v1.01-cache-2.11-cpan-13bb782fe5a )