Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
Eric Wilhelm wrote: # from Sébastien Aperghis-Tramoni # on Monday 08 October 2007 16:02: use relative; my $Customer = import relative qw(Report Customer); This changes the require() on Foo::Report and Foo::Customer to run- time though, right? Right, but I'd say that for writing object-oriented code, there isn't such a need to do things at compile time, is it? -- Sébastien Aperghis-Tramoni Close the world, txEn eht nepO.
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
--- Sébastien Aperghis-Tramoni [EMAIL PROTECTED] wrote: Hmm.. As is, relative.pm already allows you to do that (thanks to Ken Williams' suggestion): package My::Enterprise::Framework; use relative; my $Customer = import relative qw(Report Customer); my $customer = $Customer-new($id); That is, import returns the full names of the successfully loaded modules in list context, or the last one in scalar context. Is this sufficient or did I misunderstand you? Ah, I didn't notice that. I think that would be fine. The only caveat being that this is lexically scoped, but I don't *think* there is problem there. Thanks for a nice module! Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Perl and CGI - http://users.easystreet.com/ovid/cgi_course/ Personal blog - http://publius-ovidius.livejournal.com/ Tech blog - http://use.perl.org/~Ovid/journal/
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
--- A. Pagaltzis [EMAIL PROTECTED] wrote: * Eric Wilhelm [EMAIL PROTECTED] [2007-10-09 01:55]: This changes the require() on Foo::Report and Foo::Customer to run-time though, right? use Devel::BeginLift qw( require ); Cute trick, but I wondered if that would globally break require. #!/usr/bin/perl -l use strict; use warnings; use Devel::BeginLift qw(require); require Data::Dumper; BEGIN { no warnings 'once'; print $Data::Dumper::Indent; } Seems to have no impact on require at all. I suspect that's because it's not a subroutine. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Perl and CGI - http://users.easystreet.com/ovid/cgi_course/ Personal blog - http://publius-ovidius.livejournal.com/ Tech blog - http://use.perl.org/~Ovid/journal/
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
Ovid wrote: I do get tired of writing code like that (it happens a lot in test suites when I have use_ok $CLASS in a BEGIN block). OT, but 'ok.pm' is quite nice: use Test::More tests = 1; use ok 'My::Module'; # test runs at compile time Regards, Jonathan Rockway signature.asc Description: OpenPGP digital signature
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
# from A. Pagaltzis # on Monday 08 October 2007 22:50: * Eric Wilhelm [EMAIL PROTECTED] [2007-10-09 01:55]: This changes the require() on Foo::Report and Foo::Customer to run-time though, right? use Devel::BeginLift qw( require ); The import() method is calling require at run-time. That's going to take some heavy lifting ;-) --Eric -- Consumers want choice, consumers want openness. --Rob Glaser --- http://scratchcomputing.com ---
(OT) Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
--- Jonathan Rockway [EMAIL PROTECTED] wrote: OT, but 'ok.pm' is quite nice: use Test::More tests = 1; use ok 'My::Module'; # test runs at compile time Oh, I really like that, but it still causes an issue for me. You see, a lot of what I do is stuff like this: my $CLASS; BEGIN { $CLASS = 'Customer'; use_ok $CLASS or die; } can_ok $CLASS, 'new'; ok my $cust = $CLASS-new, '... and we can call it'; isa_ok $cust, $CLASS, '... and the object it returns'; This means that if I need to refactor classes to better namespaces, I merely change the $CLASS = line. With the lovely ok.pm module, I still have the following clunky construct: my $CLASS; BEGIN { $CLASS = 'Customer'; } use ok $CLASS or die; can_ok $CLASS, 'new'; ok my $cust = $CLASS-new, '... and we can call it'; isa_ok $cust, $CLASS, '... and the object it returns'; Those BEGIN blocks really annoy the hell out of me at times :( Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Perl and CGI - http://users.easystreet.com/ovid/cgi_course/ Personal blog - http://publius-ovidius.livejournal.com/ Tech blog - http://use.perl.org/~Ovid/journal/
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
# from Sébastien Aperghis-Tramoni # on Tuesday 09 October 2007 00:07: This changes the require() on Foo::Report and Foo::Customer to run- time though, right? Right, but I'd say that for writing object-oriented code, there isn't such a need to do things at compile time, is it? Probably not, but they're still different, and thus could lead to head-scratching. If the shorthand feature just installed a subroutine (what aliased does), there would be no difference. use relative 'Foo'; Foo-new; is: BEGIN { require relative; relative-import('Foo'); } Foo-new; Where the scalar usage is like: BEGIN { require relative; } my $Foo = relative-import('Foo'); $Foo-new; You can use scalars in this way (via $_[2] = 'Bar::Foo'), but they have to be declared before the use line. my $Foo; use relative Foo = $Foo; $Foo-new; So, I'm inclined to think that the sub is the way to go, though it would be nice if they went away at runtime (in order to not be accidental methods.) 5.10 and $^H anyone? --Eric -- Time flies like an arrow, but fruit flies like a banana. --Groucho Marx --- http://scratchcomputing.com ---
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
* Eric Wilhelm [EMAIL PROTECTED] [2007-10-09 09:50]: The import() method is calling require at run-time. That's going to take some heavy lifting ;-) Err, I meant `qw( import )`. Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
* Ovid [EMAIL PROTECTED] [2007-10-09 09:40]: --- A. Pagaltzis [EMAIL PROTECTED] wrote: * Eric Wilhelm [EMAIL PROTECTED] [2007-10-09 01:55]: This changes the require() on Foo::Report and Foo::Customer to run-time though, right? use Devel::BeginLift qw( require ); Cute trick, but I wondered if that would globally break require. Wrong trick, I meant to begin-lift `import`, not `require`, ugh. Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/
Re: (OT) Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
Ovid writes: With the lovely ok.pm module, I still have the following clunky construct: my $CLASS; BEGIN { $CLASS = 'Customer'; } use ok $CLASS or die; can_ok $CLASS, 'new'; ok my $cust = $CLASS-new, '... and we can call it'; isa_ok $cust, $CLASS, '... and the object it returns'; Those BEGIN blocks really annoy the hell out of me at times :( Well don't have them then -- put the assignment in the use statement, which is run at BEGIN time anyway: use Test::More tests = 1; my $CLASS; use ok $CLASS = 'DateTime'; Smylers
Re: (OT) Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
* Smylers [EMAIL PROTECTED] [2007-10-09 10:25]: Well don't have them then -- put the assignment in the use statement, which is run at BEGIN time anyway: use Test::More tests = 1; my $CLASS; use ok $CLASS = 'DateTime'; Sneaky! I like. -- *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(,$\/, )[defined wantarray]/e;$1} Just-another-Perl-hack; #Aristotle
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
Ovid wrote: --- Sébastien Aperghis-Tramoni [EMAIL PROTECTED] wrote: Eric Wilhelm wrote: use relative; my $Customer = import relative qw(Report Customer); This changes the require() on Foo::Report and Foo::Customer to run- time though, right? Right, but I'd say that for writing object-oriented code, there isn't such a need to do things at compile time, is it? You know, I hadn't considered the runtime/compile-time issue when I first saw this. Eric's right that this does change the semantics. I suppose one could wrap it in a BEGIN block, but that makes it worse: use relative; my ( $Report, $Customer ); BEGIN { ( $Report, $Customer ) = import relative qw(Report Customer); } I do get tired of writing code like that (it happens a lot in test suites when I have use_ok $CLASS in a BEGIN block). I do agree that with OO modules that compile-time should be less of an issue, but it's not universally the case. Still, I think the import relative is probably enough for me. To be honest, I'm not really convinced because I don't see why so much things should happen at compile-time, but I'll add the -aliased option in the next release. -- Sébastien Aperghis-Tramoni Close the world, txEn eht nepO.
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
--- Sébastien Aperghis-Tramoni [EMAIL PROTECTED] wrote: Hello, The version 0.02 of relative.pm is now available on the CPAN. Thanks to everybody who suggested improvements. (And it still works on Perl 5.004 :-) I like the idea of this module. Lots of people like the idea of 'aliased'. Would it be worth combining the two? use My::Enterprise::Framework; use relative -aliased = qw(Customer Report); # instead of: # my $customer = My::Enterprise::Framework::Customer-new($id); # use: my $customer = Customer-new($id); http://search.cpan.org/dist/aliased/ Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Perl and CGI - http://users.easystreet.com/ovid/cgi_course/ Personal blog - http://publius-ovidius.livejournal.com/ Tech blog - http://use.perl.org/~Ovid/journal/
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
On 8 Oct 2007, at 11:28, Ovid wrote: [snip] I like the idea of this module. Lots of people like the idea of 'aliased'. Would it be worth combining the two? use My::Enterprise::Framework; use relative -aliased = qw(Customer Report); # instead of: # my $customer = My::Enterprise::Framework::Customer-new($id); # use: my $customer = Customer-new($id); http://search.cpan.org/dist/aliased/ ++ I like. Adrian
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
Ovid wrote: I like the idea of this module. Lots of people like the idea of 'aliased'. Would it be worth combining the two? use My::Enterprise::Framework; use relative -aliased = qw(Customer Report); # instead of: # my $customer = My::Enterprise::Framework::Customer-new($id); # use: my $customer = Customer-new($id); Hmm.. As is, relative.pm already allows you to do that (thanks to Ken Williams' suggestion): package My::Enterprise::Framework; use relative; my $Customer = import relative qw(Report Customer); my $customer = $Customer-new($id); That is, import returns the full names of the successfully loaded modules in list context, or the last one in scalar context. Is this sufficient or did I misunderstand you? -- Sébastien Aperghis-Tramoni Close the world, txEn eht nepO.
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
# from Sébastien Aperghis-Tramoni # on Monday 08 October 2007 16:02: use relative; my $Customer = import relative qw(Report Customer); This changes the require() on Foo::Report and Foo::Customer to run-time though, right? If only we had userland pragmas, you could just create functions Report and Customer and delete them in unimport(). use relative qw(Report Customer); ... my $c = Customer-new(); my $r = Report-new() ... no relative; --Eric -- ...the bourgeoisie were hated from both ends: by the proles, because they had all the money, and by the intelligentsia, because of their tendency to spend it on lawn ornaments. --Neal Stephenson --- http://scratchcomputing.com ---
Re: S/SA/SAPER/relative-0.02.tar.gz (feature request)
* Eric Wilhelm [EMAIL PROTECTED] [2007-10-09 01:55]: This changes the require() on Foo::Report and Foo::Customer to run-time though, right? use Devel::BeginLift qw( require ); :- Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/