Hi

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?

EDIT

at hindsight %INC and @INC might be useful ... (?)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!


In reply to [DSL] disabling packages in Perl? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.