G'day rumpumpel1,

"how can I systematically find the module, in which the login function appears?"

In whatever OO hierarchy you have, it's entirely possible that any method could be present in more than one class. I'm going to assume you mean the class where the method is found first according to whatever method resolution order you're using. See "mro - Method Resolution Order" for more about that; and for any questions you might have regarding how I've used that pragma in the following code.

#!/usr/bin/env perl use 5.010; use strict; use warnings; package A; sub new { bless {} => $_[0] } sub seen_once { 1 } sub seen_twice { 1 } sub seen_thrice { 1 } package A::B; use parent -norequire => 'A'; sub seen_twice { 1 } sub seen_thrice { 1 } package A::B::C; use parent -norequire => 'A::B'; sub seen_thrice { 1 } package main; use mro; my $instantiation_class = 'A::B::C'; my @methods = qw{seen_once seen_twice seen_thrice seen_never}; my $isa = mro::get_linear_isa($instantiation_class); my %found; say "Instantiation class: $instantiation_class"; my $obj = $instantiation_class->new; say 'Objects blessed into class: ', ref $obj; say 'Method Resolution:'; METHOD: for my $method (@methods) { next METHOD if exists $found{$method}; CLASS: for my $class (@$isa) { { no strict 'refs'; next CLASS unless exists ${$class . '::'}{$method}; } ++$found{$method}; say "$method()\tfound first in $class"; last CLASS; } unless (exists $found{$method}) { say "$method()\tNOT found in OO hierarchy!"; } }


Instantiation class: A::B::C Objects blessed into class: A::B::C Method Resolution: seen_once() found first in A seen_twice() found first in A::B seen_thrice() found first in A::B::C seen_never() NOT found in OO hierarchy!

Update: After posting I thought the "Objects blessed into class: A" looked a bit odd; then realised I'd screwed up the constructor: "sub new { bless {} => __PACKAGE__ }". I've fixed that (now: sub new { bless {} => $_[0] }); after rerunning, the output now has "Objects blessed into class: A::B::C" (which looks somewhat saner). None of the other code or output has changed.

— Ken

In reply to Re: how to find the module of a specific function? by kcott
in thread how to find the module of a specific function? by rumpumpel1

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":