I have a class called XYZServer that I want to use to intercept (and divert) calls to another package my XYZServer package looks like this....
sub new { my $proto = shift; # Get the Prototype my $class = ref ($proto) || $proto; # Make the Class Name my $parent= ref ($proto) && $proto; # Get the Parent Class + (if Any) my $self = {}; # Create the HASH for +the Object bless($self, $class); # Create the Object $self->{_PARENT}= $parent; $self->{_RESULT} = ""; # Result of the method + call $self->{_STATUS} = 0; # Status Return (0 = O +K) $self->{SERVER} = XXX->new(); return $self; # Return the Object Ref +erence } sub allowed_function { my $self = shift; my $function = shift; if ($function eq "sane") { return(1) ; } else { return(0); } } sub AUTOLOAD { my $self = shift; my $thing = $AUTOLOAD; $thing =~ s/.*:://g; return if $AUTOLOAD =~ /DESTROY$/; if ($self->allowed_function($thing) { $self->{SERVER}->$AUTOLOAD(@_); } }
If I have a method called 'sane', and one called 'insane' that is defined in the XXX module, I want to do the following
my $X = XYZServer->new; my $sane; $sane = $X->sane;
I want the routine to execute, but if I say
$sane = $X->insane;
I want it not to execute the routine !! I have been racking my brain oh how to do this, but it has me stumped.

In reply to Filtering access to an Objects functions by CTSMan

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.