LanX has asked for the wisdom of the Perl Monks concerning the following question:
is there a way to (temporarily) disable packages?
let's say I wanted to create a DSL for SQL, this partial clause would be legal in Perl
sub WHERE(&;$); WHERE { a IN [1,2,3] or b LIKE '%abc%' };
and the block would be parsed as indirect method syntax
'IN'->a([1, 2, 3]) or 'LIKE'->b('%abc%');
so I'd need to define packages IN and LIKE to simulate binary operators when executing the BLOCK
DB<198> {package LIKE; sub AUTOLOAD { my ($field) = $AUTOLOAD =~ m/\ +w+::(\w+)/; print "$field @_" }} DB<199> field LIKE '%abc%' field LIKE %abc%
so far so good ... but is there a possibility to "disable" the package outside of the block's scope?
The best thing I came up was redefining AUTOLOAD dynamically before and after executing the block to provoke a runtime error
deleting the stash entry for the package in %main:: produced strange problems, probably because of some kind of cashing...
any ideas?
at hindsight %INC and @INC might be useful ... (?)
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [DSL] disabling packages in Perl? (updated)
by haukex (Archbishop) on Apr 18, 2016 at 17:58 UTC | |
by LanX (Saint) on Apr 19, 2016 at 12:55 UTC | |
by haukex (Archbishop) on Apr 23, 2016 at 20:28 UTC | |
by LanX (Saint) on Apr 21, 2016 at 15:38 UTC | |
|
Re: [DSL] disabling packages in Perl?
by shmem (Chancellor) on Apr 18, 2016 at 19:19 UTC | |
|
Re: [DSL] disabling packages in Perl?
by mlawren (Sexton) on Apr 19, 2016 at 12:56 UTC | |
by LanX (Saint) on Apr 19, 2016 at 14:33 UTC | |
by mlawren (Sexton) on Apr 19, 2016 at 21:14 UTC |