<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
<div><br></div>coloque o seguinte no seu código...<div><br></div><div>use lib '/path/para/diretório/arquivos/.pm';</div><div><br></div><div>... e descomente o require.</div><div>Acredito que isso deve funcionar.<br><br></div><div>Ua,<br><br><font face="Verdana">Daniel Vinciguerra - Developer<br><a href="http://github.com/dvinciguerra" target="_blank">http://github.com/dvinciguerra</a><br></font><div class="ecxvimiumHUD" style="right:150px;zoom:100%"><br></div><br><br><br><br>> Date: Tue, 7 Dec 2010 16:02:47 -0200<br>> From: mantovani@perl.org.br<br>> To: cascavel-pm@pm.org<br>> Subject: Re: [Cascavel-pm] Reflexão em Perl<br>> <br>> Você tem um arquivo chamado Foo.pm no mesmo diretório do script.pl que<br>> está fazendo o require ?<br>> <br>> 2010/12/7 Tom Mostard <capmostarda@gmail.com>:<br>> ><br>> > Daniel,<br>> > Obrigado pela ajuda! Mas aqui continuar sem solução.<br>> ><br>> > package Foo;<br>> ><br>> > sub new { return bless {}, shift }<br>> > sub method { my $self = shift; print "Work!\n" }<br>> ><br>> > 1;<br>> ><br>> ><br>> > package main;<br>> ><br>> > my ( $class, $method ) = ( 'Foo', 'method' );<br>> > # require $class;<br>> > $class->new->$method;<br>> ><br>> ><br>> > Quando uso o require acima, tenho a seguinte mensagem:<br>> > Can't locate Foo in @INC (@INC contains: /etc/perl<br>> > /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5<br>> > /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10<br>> > /usr/local/lib/site_perl .) at ./main.pl line 6.<br>> ><br>> > Se eu comento o "require", tenho a seguinte mensagem:<br>> > Can't locate object method "new" via package "Foo" (perhaps you forgot to<br>> > load "Foo"?) at ./main.pl line 7.<br>> ><br>> > Será que preciso instalar algum módulo? Ainda não tentei o Class::MOP nem o<br>> > Moose. Queria resolver isso sem usá-los, se for possível.<br>> > Se uso as duas classes num único arquivo, funciona, mas minha intenção é<br>> > usar uma classe externa, que pode variar conforme a necessidade.<br>> ><br>> > Mais uma vez, obrigado.<br>> ><br>> > Tom<br>> ><br>> > Em 7 de dezembro de 2010 02:38, Daniel de Oliveira Mantovani<br>> > <mantovani@perl.org.br> escreveu:<br>> >><br>> >> Abusando da lista, e mandando 1 milhão de e-mail na mesma thread, vou<br>> >> deixar só a última recomendação,<br>> >> http://en.wikipedia.org/wiki/Metaprogramming<br>> >><br>> >> Eu gostaria de falar muito mais sobre reflexão e introspecção, mas<br>> >> preciso trabalhar.<br>> >><br>> >> Boa noite.<br>> >><br>> >> 2010/12/7 Daniel de Oliveira Mantovani <mantovani@perl.org.br>:<br>> >> > Ops, esqueci de colocar o link do manual do Moose,<br>> >> > http://search.cpan.org/~drolsky/Moose-1.21/lib/Moose/Manual.pod<br>> >> ><br>> >> > Só para ficar mais claro, você pode usar toda a magia do Moose e ainda<br>> >> > abusar de reflexão e introspecção, com Class::Mop.<br>> >> ><br>> >> > 2010/12/7 Daniel de Oliveira Mantovani <mantovani@perl.org.br>:<br>> >> >> Perl é arte, você pode usar toda a magia do Moose e abusar de reflexão<br>> >> >> e introspecção:<br>> >> >><br>> >> >> use Some::Class;<br>> >> >> use Class::MOP;<br>> >> >><br>> >> >> my $meta = Class::MOP::Class->initialize('Some::Class');<br>> >> >><br>> >> >> for my $meth ( $meta->get_all_methods ) {<br>> >> >> print $meth->fully_qualified_name, "\n":<br>> >> >> }<br>> >> >><br>> >> >><br>> >> >> 2010/12/7 Daniel de Oliveira Mantovani <mantovani@perl.org.br>:<br>> >> >>> 2010/12/7 Tom Mostard <capmostarda@gmail.com>:<br>> >> >>>> Colegas,<br>> >> >>>><br>> >> >>>> Alguém sabe como carregar uma classe que não foi carregada com "use"<br>> >> >>>> através<br>> >> >>>> de reflexão computacional?<br>> >> >>><br>> >> >>> package Foo;<br>> >> >>><br>> >> >>> sub new { return bless {}, shift }<br>> >> >>> sub method { my $self = shift; print "Work!\n" }<br>> >> >>><br>> >> >>> 1;<br>> >> >>><br>> >> >>> package main;<br>> >> >>><br>> >> >>> my ( $class, $method ) = ( 'Foo', 'method' );<br>> >> >>> $class->new->$method;<br>> >> >>><br>> >> >>><br>> >> >>> __END__<br>> >> >>><br>> >> >>><br>> >> >>> Outro exemplo, http://nopaste.snit.ch/26735<br>> >> >>><br>> >> >>>> Sei que Perl suporta, mas não estou conseguindo implementar.<br>> >> >>>><br>> >> >>>> Exemplo:<br>> >> >>>><br>> >> >>>> my $class = "Foo";<br>> >> >>>> my $method = "hello";<br>> >> >>>> my $object = $class->new();<br>> >> >>>> $object->$method(); // que e o mesmo que $object->hello();<br>> >> >>>><br>> >> >>>> Implementei a classe Foo, e salvei no mesmo diretório como Foo.pm<br>> >> >>>> Preciso usar o EXPORT ou coisa assim?<br>> >> >>><br>> >> >>> Não, você não precisa do Export. Você pode usar "do" ou "require".<br>> >> >>><br>> >> >>> package main;<br>> >> >>> use strict;<br>> >> >>> use warnings;<br>> >> >>><br>> >> >>> my %cm = (qw/Foo read Bar people Baz should/);<br>> >> >>><br>> >> >>> foreach my $class ( ( sort keys %cm ) ) {<br>> >> >>><br>> >> >>> require $class;<br>> >> >>> my $method = $cm{$class};<br>> >> >>><br>> >> >>> $class->new->$method;<br>> >> >>><br>> >> >>> }<br>> >> >>><br>> >> >>> Uma das utilidades do "require", é quando você precisa carregar um<br>> >> >>> módulo em tempo de execução, que é o seu caso.<br>> >> >>> Na verdade, tanto "use" como "require" usam o "do". Ambos são uma<br>> >> >>> abstração.<br>> >> >>> http://perldoc.perl.org/functions/do.html<br>> >> >>><br>> >> >>><br>> >> >>><br>> >> >>>><br>> >> >>>> O erro que tenho é o seguinte:<br>> >> >>>><br>> >> >>>> Can't locate object method "new" via package "Foo" (perhaps you<br>> >> >>>> forgot to<br>> >> >>>> load "Foo"?) at ./main.pl line 10.<br>> >> >>>><br>> >> >>>> Mas se eu uso o "use Foo" funciona.<br>> >> >>>><br>> >> >>>> Abraços,<br>> >> >>>><br>> >> >>>> Tom<br>> >> >>>> _______________________________________________<br>> >> >>>> Cascavel-pm mailing list<br>> >> >>>> Cascavel-pm@pm.org<br>> >> >>>> http://mail.pm.org/mailman/listinfo/cascavel-pm<br>> >> >>>><br>> >> >>><br>> >> >>><br>> >> >>><br>> >> >>> --<br>> >> >>> "If you’ve never written anything thoughtful, then you’ve never had<br>> >> >>> any difficult, important, or interesting thoughts. That’s the secret:<br>> >> >>> people who don’t write, are people who don’t think."<br>> >> >>><br>> >> >><br>> >> >><br>> >> >><br>> >> >> --<br>> >> >> "If you’ve never written anything thoughtful, then you’ve never had<br>> >> >> any difficult, important, or interesting thoughts. That’s the secret:<br>> >> >> people who don’t write, are people who don’t think."<br>> >> >><br>> >> ><br>> >> ><br>> >> ><br>> >> > --<br>> >> > "If you’ve never written anything thoughtful, then you’ve never had<br>> >> > any difficult, important, or interesting thoughts. That’s the secret:<br>> >> > people who don’t write, are people who don’t think."<br>> >> ><br>> >><br>> >><br>> >><br>> >> --<br>> >> "If you’ve never written anything thoughtful, then you’ve never had<br>> >> any difficult, important, or interesting thoughts. That’s the secret:<br>> >> people who don’t write, are people who don’t think."<br>> >> _______________________________________________<br>> >> Cascavel-pm mailing list<br>> >> Cascavel-pm@pm.org<br>> >> http://mail.pm.org/mailman/listinfo/cascavel-pm<br>> ><br>> ><br>> > _______________________________________________<br>> > Cascavel-pm mailing list<br>> > Cascavel-pm@pm.org<br>> > http://mail.pm.org/mailman/listinfo/cascavel-pm<br>> ><br>> <br>> <br>> <br>> -- <br>> "If you’ve never written anything thoughtful, then you’ve never had<br>> any difficult, important, or interesting thoughts. That’s the secret:<br>> people who don’t write, are people who don’t think."<br>> _______________________________________________<br>> Cascavel-pm mailing list<br>> Cascavel-pm@pm.org<br>> http://mail.pm.org/mailman/listinfo/cascavel-pm<br></div>                                            </body>
</html>