Calling class methods from a metaclass

[email protected] ("Dan Harbin")
Newsgroups perl.moose
Message-ID <[email protected]>
The following:

    #!/usr/bin/env perl
    use strict;
    use warnings;

    package MyClass;
    {
      use Moose;

      sub hello_class {
        my $class = shift;
        return  "Hello $class\n";
      }
    }

    print "1: ", MyClass->hello_class(), "\n";

    my $myclass = Class::MOP::get_metaclass_by_name('MyClass');

    print "2: ", $myclass->hello_class(), "\n";


Gives:

    1: Hello MyClass

    Can't locate object method "hello_class" via package
"Moose::Meta::Class" at ./example.pl line 19.


Is there any way to call a class method when I don't know the package
name at runtime?

Thanks,
Dan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.