Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

headers!

3 views
Skip to first unread message

Paul

unread,
Apr 28, 2003, 10:04:01 AM4/28/03
to perl6-l...@perl.org

Ok, one thing that has amused me (maybe this is a tiny contribution to
the "What sux about Perl thread?) is that if I know that I'll always
want *these* six use() statements in virtually every program I ever
write, I have to type them all in every time. (Do I hear a "poor baby"
out there? :)

So, as a personal solution, I wrote a quick little script I use called
new.pl which takes the name of a new script as an argument, creates
that file with a header containing those standard use() statements, a
standard template for calling a function in one of them which provides
usage data about the program if run with no arguments, some comments
about who wrote the program and when, and if it were already there
updates when last edited, and stuff like that. It also opens the code
in vi in a subshell, and when you exits it syntax checks it and
archives it. Lots of automation, but not something you want to do
*every* time you edit a file. Also, that script isn't installed
everywhere I go, and I don't want to have to rewrite the whole blooming
thing....

So I was thinking....

I know you can't put use() statements into a file and use() that....
but maybe now, with P6, you can!

Couldn't I write a module with an import that changes into the
namespace of the caller and them runs a macro to load a list of other
modules specified in the macro?

Or have I gone completely off the deep end and into the realm of Evil
Black Magic now?

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

Austin Hastings

unread,
Apr 28, 2003, 10:31:32 AM4/28/03
to Hod...@writeme.com, perl6-l...@perl.org
I recall, when the world was young, some discussion about having
something like "site.pl" which would do a lot of this sort of thing for
you.

At the time, everyone poo-poo'ed it, since it would stifle creativity
or some other grabasstic excuse.

Now, with the prospect of having "standard grammar mods" (such as
literal TRUE/FALSE values) in use as sort of a company coding standard
kind of thing, I suspect the capability will get revisited.

=Austin

Luke Palmer

unread,
Apr 28, 2003, 3:40:20 PM4/28/03
to Hod...@writeme.com, perl6-l...@perl.org
> Ok, one thing that has amused me (maybe this is a tiny contribution to
> the "What sux about Perl thread?) is that if I know that I'll always
> want *these* six use() statements in virtually every program I ever
> write, I have to type them all in every time. (Do I hear a "poor baby"
> out there? :)
>
> So, as a personal solution, I wrote a quick little script I use called
> new.pl which takes the name of a new script as an argument, creates
> that file with a header containing those standard use() statements, a
> standard template for calling a function in one of them which provides
> usage data about the program if run with no arguments, some comments
> about who wrote the program and when, and if it were already there
> updates when last edited, and stuff like that. It also opens the code
> in vi in a subshell, and when you exits it syntax checks it and
> archives it. Lots of automation, but not something you want to do
> *every* time you edit a file. Also, that script isn't installed
> everywhere I go, and I don't want to have to rewrite the whole blooming
> thing....
>
> So I was thinking....
>
> I know you can't put use() statements into a file and use() that....
> but maybe now, with P6, you can!

Er, you can in P5. You just need to do a little extra work in that
file:

package MyModules;

use Exporter;
use base 'Exporter';

use SomeModule;
use OtherModule;

our @EXPORT = (@SomeModule::EXPORT, @OtherModule::EXPORT);

For things like file scoped pragmas it doesn't work, though :(

> Couldn't I write a module with an import that changes into the
> namespace of the caller and them runs a macro to load a list of other
> modules specified in the macro?
>
> Or have I gone completely off the deep end and into the realm of Evil
> Black Magic now?

Yeah, but Evil Black Magic is a Perl forte.

Luke

Paul

unread,
Apr 28, 2003, 5:28:20 PM4/28/03
to Luke Palmer, perl6-l...@perl.org

--- Luke Palmer <fibo...@babylonia.flatirons.org> wrote:
> > Ok, one thing that has amused me (maybe this is a tiny contribution
> > to the "What sux about Perl thread?) is that if I know that I'll
> > always want *these* six use() statements in virtually every program
> > I ever write, I have to type them all in every time. (Do I hear a
> > "poor baby" out there? :)
> > [...]

> > I know you can't put use() statements into a file and use()
> > that.... but maybe now, with P6, you can!
>
> Er, you can in P5. You just need to do a little extra work in that
> file:
>
> package MyModules;
> use Exporter;
> use base 'Exporter';
> use SomeModule;
> use OtherModule;
> our @EXPORT = (@SomeModule::EXPORT, @OtherModule::EXPORT);

That's neat -- hadn't thought of that.
The thing is, though, I don't like to export anything, practically
ever.

> For things like file scoped pragmas it doesn't work, though :(

And I was trying for a solution that would even allow lexicals.



> > Couldn't I write a module with an import that changes into the
> > namespace of the caller and them runs a macro to load a list of
> > other modules specified in the macro?
> > Or have I gone completely off the deep end and into the realm of
> > Evil Black Magic now?
>
> Yeah, but Evil Black Magic is a Perl forte.
> Luke

lol -- Good Paul sez:
"but you should never invade someone else's namespace!"

Evil Paul sez:
"what's with this 'someone else' crap? It's MINE!"
<evil Mwuahahahahaaa laugh, trailing off to a commercial....>

Joseph F. Ryan

unread,
Apr 28, 2003, 6:56:20 PM4/28/03
to Hod...@writeme.com, perl6-l...@perl.org
Paul wrote:

What's wrong with creating a module like this?

package SuperUser;

sub import {
my $pkg = (caller)[0];
eval qq(
package $pkg;
use Foo;
use Bar;
use Baz;
use Quux;
use Perl6;
);
}

1;

# and then...

use SuperUser;

This works fine in Perl5, and its not exactly "deep magic."

- Joe

Paul

unread,
Apr 28, 2003, 9:06:14 PM4/28/03
to Joseph F. Ryan, perl6-l...@perl.org

--- "Joseph F. Ryan" <ryan...@osu.edu> wrote:
> Paul wrote:
>
> >Ok, one thing that has amused me (maybe this is a tiny contribution
> > to the "What sux about Perl thread?) is that if I know that I'll
> > always want *these* six use() statements in virtually every program

> > I ever write, I have to type them all in every time. (Do I hear a
> > "poor baby" out there? :)

> > [...]


> >I know you can't put use() statements into a file and use() that....
> >but maybe now, with P6, you can!
> >
> > Couldn't I write a module with an import that changes into the
> > namespace of the caller and them runs a macro to load a list of
> > othermodules specified in the macro?
>

> What's wrong with creating a module like this?
>
> package SuperUser;
>
> sub import {
> my $pkg = (caller)[0];
> eval qq(
> package $pkg;
> use Foo;
> use Bar;
> use Baz;
> use Quux;
> use Perl6;
> );
> }
>
> 1;
>
> # and then...
>
> use SuperUser;
>
> This works fine in Perl5, and its not exactly "deep magic."

I think I misrepresented the problem.
I was trying to think of a solution that would also allow lexicals to
be created and initialized, though I suspect I just didn't understand
my question, lol....

It's been a day. :)

Joseph F. Ryan

unread,
Apr 29, 2003, 12:28:12 AM4/29/03
to Hod...@writeme.com, perl6-l...@perl.org
Paul wrote:

Well, you can just use Perl6's caller to grab the caller's %MY::, and
then modify that...

- Joe

Paul

unread,
Apr 29, 2003, 9:37:23 AM4/29/03
to Joseph F. Ryan, perl6-l...@perl.org
> >>What's wrong with creating a module like this?
> >>
> >> package SuperUser;
> >>
> >> sub import {
> >> my $pkg = (caller)[0];
> >> eval qq(
> >> package $pkg;
> >> use Foo;
> >> use Bar;
> >> use Baz;
> >> use Quux;
> >> use Perl6;
> >> );
> >> }
> >>
> >> 1;
> >>
> >> # and then...
> >>
> >> use SuperUser;
> >>
> >>This works fine in Perl5, and its not exactly "deep magic."
> >
> > I think I misrepresented the problem.
> > I was trying to think of a solution that would also allow
> > lexicals to be created and initialized, though I suspect I
> > just didn't understand my question, lol....
>
> Well, you can just use Perl6's caller to grab the caller's %MY::, and
> then modify that...

*THAT*'s what I was looking for!
So not I *can* do a full-blown preinitialization, complete with
preloaded modules and lexical setup in the scope of the base script.
Beautiful!

Marco Baringer

unread,
Apr 29, 2003, 8:50:35 AM4/29/03
to perl6-l...@perl.org
Paul <ydb...@yahoo.com> writes:

> I know you can't put use() statements into a file and use() that....
> but maybe now, with P6, you can!

what's wrong with something along the lines of:

macro include ($file) {
join '', <open $file>;
}

--
-Marco
Ring the bells that still can ring.
Forget your perfect offering.
There is a crack in everything.
That's how the light gets in.
-Leonard Cohen

Paul

unread,
Apr 29, 2003, 9:50:43 AM4/29/03
to Marco Baringer, perl6-l...@perl.org

--- Marco Baringer <m...@bese.it> wrote:
> Paul <ydb...@yahoo.com> writes:
> > I know you can't put use() statements into a file and use()
> > that.... but maybe now, with P6, you can!
>
> what's wrong with something along the lines of:
>
> macro include ($file) {
> join '', <open $file>;
> }

Exactly!

0 new messages