Isso mesmo.<br><br><div class="gmail_quote">Em 7 de dezembro de 2010 15:02, Daniel de Oliveira Mantovani <span dir="ltr"><<a href="mailto:mantovani@perl.org.br">mantovani@perl.org.br</a>></span> escreveu:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Você tem um arquivo chamado Foo.pm no mesmo diretório do <a href="http://script.pl" target="_blank">script.pl</a> que<br>
está fazendo o require ?<br>
<div><div></div><div class="h5"><br>
2010/12/7 Tom Mostard <<a href="mailto:capmostarda@gmail.com">capmostarda@gmail.com</a>>:<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 ./<a href="http://main.pl" target="_blank">main.pl</a> 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 ./<a href="http://main.pl" target="_blank">main.pl</a> 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>
> <<a href="mailto:mantovani@perl.org.br">mantovani@perl.org.br</a>> 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>
>> <a href="http://en.wikipedia.org/wiki/Metaprogramming" target="_blank">http://en.wikipedia.org/wiki/Metaprogramming</a><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 <<a href="mailto:mantovani@perl.org.br">mantovani@perl.org.br</a>>:<br>
>> > Ops, esqueci de colocar o link do manual do Moose,<br>
>> > <a href="http://search.cpan.org/%7Edrolsky/Moose-1.21/lib/Moose/Manual.pod" target="_blank">http://search.cpan.org/~drolsky/Moose-1.21/lib/Moose/Manual.pod</a><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 <<a href="mailto:mantovani@perl.org.br">mantovani@perl.org.br</a>>:<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 <<a href="mailto:mantovani@perl.org.br">mantovani@perl.org.br</a>>:<br>
>> >>> 2010/12/7 Tom Mostard <<a href="mailto:capmostarda@gmail.com">capmostarda@gmail.com</a>>:<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, <a href="http://nopaste.snit.ch/26735" target="_blank">http://nopaste.snit.ch/26735</a><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>
>> >>> <a href="http://perldoc.perl.org/functions/do.html" target="_blank">http://perldoc.perl.org/functions/do.html</a><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 ./<a href="http://main.pl" target="_blank">main.pl</a> 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>
>> >>>> <a href="mailto:Cascavel-pm@pm.org">Cascavel-pm@pm.org</a><br>
>> >>>> <a href="http://mail.pm.org/mailman/listinfo/cascavel-pm" target="_blank">http://mail.pm.org/mailman/listinfo/cascavel-pm</a><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>
>> <a href="mailto:Cascavel-pm@pm.org">Cascavel-pm@pm.org</a><br>
>> <a href="http://mail.pm.org/mailman/listinfo/cascavel-pm" target="_blank">http://mail.pm.org/mailman/listinfo/cascavel-pm</a><br>
><br>
><br>
> _______________________________________________<br>
> Cascavel-pm mailing list<br>
> <a href="mailto:Cascavel-pm@pm.org">Cascavel-pm@pm.org</a><br>
> <a href="http://mail.pm.org/mailman/listinfo/cascavel-pm" target="_blank">http://mail.pm.org/mailman/listinfo/cascavel-pm</a><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>
<a href="mailto:Cascavel-pm@pm.org">Cascavel-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/cascavel-pm" target="_blank">http://mail.pm.org/mailman/listinfo/cascavel-pm</a><br>
</div></div></blockquote></div><br>