I don't know if you are still seeing replies, since I don't know how to get notified of replies to my replies other than to go find each thread I've written in and look for them, BUT, I'll try to clarify again. In my setup, I'm doing this (not copied from code, but written for demonstration, so if everything doesn't run, that's why):
package MyPackage; our $global=0; sub global { shift; $global=$_[0] if @_; $global; } sub instance { my $this=shift; if (@_) { $this->{instance}=$_[0]; ++$global; } $instance; } sub new { my $package=shift; bless {},$package; } } package main; my $package = new MyPackage(); #main *doesn't* know what vars are per-class or which are per-instance +. # that's an implementation detail the caller doesn't know about # so all calls are called through method calls. $package->instance(1.7); print "vars created = ",$package->global; ... # reset MyPackage counter to globally reset counter for all users # (not normal used; be available for better user control of counting.. +. $package->global(0); ...
Is your complaint that I'm setting my global in a method call? That is intentional. In this situation, callers don't know the details of some variables -- whether they are per-class or per-instance. I am aware, that a caller could call an initializer function more than once. But in the use of the class, this would be an abnormal occurrence -- supported for development purposes, but not normally used.

Later, if I thought it was necessary, I could change the global definition and make some 'global_readonly', that only provides a 'get' function if I thought it necessary, but for now, I'm providing both.

I feel like we are playing 20 questions -- I keep trying to see if 'X' is what you are talking about. You keep saying 'wrong', 'its a mess'. But you don't clearly explain why its a mess. This isn't as helpful for me as your first explanation was on my prior question -- sorry.


In reply to Re^6: More Macro work...out to export a definition to next-outer level? by perl-diddler
in thread More Macro work...out to export a definition to next-outer level? by perl-diddler

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.