Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^6: Which internal DSL are there in Perl? (Domain Specific Languages - Part 1)

by soonix (Canon)
on Aug 04, 2017 at 13:16 UTC ( [id://1196726]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Which internal DSL are there in Perl? (Domain Specific Languages - Part 1)
in thread Which internal DSL are there in Perl? (Domain Specific Languages - Part 1)

Is there a way to get at the name of the lexically surrounding package inside package Page ?
To further beech's hint in the CB: perlmod says
The scope of the package declaration is … until the next package declaration.
which basically means packages can't surround each other, your packages Test and Page are on the same level.

Replies are listed 'Best First'.
Re^7: Which internal DSL are there in Perl? (Domain Specific Languages - Part 1)
by shmem (Chancellor) on Aug 04, 2017 at 13:37 UTC
    packages can't surround each other, your packages Test and Page are on the same level.

    I know that packages don't nest, and that namespaces are not organized in a hierarchy. What I am after is information about when package switching occurs, and after switching, whence. This information must be known to the compiler to restore the previous package's scope after the current package's scope ends:

    package Foo { ... package Bar { ... # I want to know 'whence' here }; ... # package Foo resumed. ... # the compiler knows about the package to be resumed. ... # how can I use that information inside 'Bar'? };
    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^7: Which internal DSL are there in Perl? (Domain Specific Languages - Part 1)
by hobbs (Monk) on Aug 04, 2017 at 14:28 UTC
    The ellipses are enough to make that quote inaccurate. This is a package with a block, which means it continues until the end of the block. Which means that at the end of the block, things go back to being in the surrounding package.
      I don't think so. Yes, it's a partial quote, but what I left off (end of surrounding block etc.) doesn't change much. When a package begins, the previous package ends. As I understand it, at end of enclosing block, the package ends, and you are in package main.
      Update: I was completely wrong, see below...
        As I understand it, at end of enclosing block, the package ends, and you are in package main.

        No. You are back in the package you came from:

        package Foo { print "(1) package " . __PACKAGE__ . $/; package Bar { print "(2) package " . __PACKAGE__ . $/; } print "(3) package " . __PACKAGE__ . $/; } print "(4) package " . __PACKAGE__ . $/; __END__ (1) package Foo (2) package Bar (3) package Foo (4) package main
        perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1196726]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-16 20:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found