Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Can I share instance through Moose::Role ?

by Anonymous Monk
on Feb 10, 2014 at 14:06 UTC ( [id://1074241]=note: print w/replies, xml ) Need Help??


in reply to Re: Can I share instance through Moose::Role ?
in thread Can I share instance through Moose::Role ?

Hello tobyink,

Thanks for your reply, your solution is simple and elegance. Regarding "tie" function, I was tried to track other scripts that may change %ENV in that way, and now it seems much simple to do this in modifiers. :)

  • Comment on Re^2: Can I share instance through Moose::Role ?

Replies are listed 'Best First'.
Re^3: Can I share instance through Moose::Role ?
by tobyink (Canon) on Feb 10, 2014 at 14:10 UTC

    When you write \%ENV you get a "live" reference to the hash %ENV. Any further changes to %ENV will be reflected in \%ENV.

    Example:

    $ENV{FOO} = 1; my $ref = \%ENV; # Change something in %ENV $ENV{FOO} = 2; print $ref->{FOO}, "\n"; # prints 2.

    If you actually need to check other scripts changing %ENV, you're out of luck. That's not how Unix environment variables work. Each process gets its own copy of the environment, cloned from its parent process. Any changes it makes to its environment cannot be seen by its parent process, nor its sibling processes. Its child processes will of course see the changes in their own cloned copies of the environment, but they cannot pass back any of their own changes.

    If you actually need to communicate changes to %ENV between processes, then you need to look into interprocess communication (IPC). This is usually accomplished by reading from and writing to Unix sockets (which are essentially filehandles used for communication between processes on the same machine) or TCP sockets (which are Unix sockets generalized to work over the Internet).

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

      Hi tobyink,

      Thanks for your great help. Those details are really helpful to me and other people.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-23 22:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found