jorba has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to determine what type of module an object is.

if I have an AXDocument module is there a parameter like $self-ModuleName which will return "AXDocument"

e.g.
package AXControl; use Moose; #Object Attributes has 'System' => (is => 'rw', isa => 'Str', required => 1); has 'ToolsHandle' => (is => 'rw', isa => 'Object'); has 'SysHandle' => (is => 'rw', isa => 'Object'); sub BUILD { $self->shift; # should print "This module is a AXControl module.\n"; print "This module is a " . $self->ModuleName . " module.\n"; }

As a follow up, if the first question is not barking mad, is there also a way to interrogate the attributes of the module and their nature?

Replies are listed 'Best First'.
Re: Moose identify module type
by stevieb (Canon) on Mar 16, 2018 at 20:30 UTC

    You can use the ref function for that:

    use warnings; use strict; package Greetings; { sub new { return bless {}, shift; } } package main; my $obj = Greetings->new; print "object is of " . ref($obj) . " class\n";

    Output:

    object is of Greetings class
Re: Moose identify module type
by choroba (Cardinal) on Mar 16, 2018 at 23:54 UTC
    Why do you need it? Normally, you should just check whether the object inherits from a class you know (via $obj->isa('Class')) or has composed a role you know (via $obj->does('Role')).

    To check the attributes, you need the $obj->meta->get_attribute_list (or even get_all_attributes for inherited ones). See Class::MOP::Class.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Gents (or Ladies) Thanx very much, you've given me more than I needed Jorb