Perl Class simple problem

From: Graeme McLaren (iamnotregistered_at_hotmail.com)
Date: 05/29/04

  • Next message: Randal L. Schwartz: "Re: The >> operator"
    To: beginners@perl.org
    Date: Sat, 29 May 2004 13:10:12 +0100
    
    

    Afternoon all, I'm trying to write a class for configuration values for
    different sites so that they can use the same conf class, then create an
    object and get whatever value they need.

    The problem I have this:

    I create an object and pass a value to my constructor like this:
    Conf->new(site=>'x'), this tells the constructor which site I want the
    config for, then at the end of the constructor I call $self->_init();
    This passes a reference to $self ( I think ) using $self = shift; When I
    die out using: die %{$self};
    I get the value that "x" equals ( x => '/usr/local/apache/htdocs/x' ) I
    need to perform additional logic in $self->_init(); and what I really need
    to do is get the name, which in this case is "x" instead of the value which
    in this case is "/usr/local/apache/htdocs/x". How do I do this I'm a bit
    lost with perl OO programming :(

    Thank you for any light anyone can shed on this.

    Graeme :)

    ################ Perl Code #################

    sub new{
        my ($caller, %arg) = @_;
        my $conv = {
          x => '/usr/local/apache/htdocs/x',
          y => '/usr/local/apache/htdocs/y',
          z => '/usr/local/apache/htdocs/z'
        };
        my $caller_is_obj = ref($caller);
        my $class = $caller_is_obj || $caller;
        my $self = bless {}, $class;
        $self->{_doc_root} = $conv->{$arg{site}||'x'};
        if(!exists $conv->{$arg{site}}){
           die "check for typos in yer params";
        }
        $self->_init();
    }

    sub _init{
      my $self = shift;
      die %{$self};
    }
    ##################### End of Perl Code ####################

    _________________________________________________________________
    Get a FREE connection, FREE modem and one month's FREE line rental, plus a
    US or European flight when you sign up for BT Broadband!
    http://www.msn.co.uk/specials/btbroadband


  • Next message: Randal L. Schwartz: "Re: The >> operator"

    Relevant Pages

    • Re: Java Logger
      ... I am not using a console Handler in the code, ... it is not Java code. ... reading in the initial configuration. ... In other words, copy the code posted by Knute to the constructor of a class, say ...
      (comp.lang.java.programmer)
    • Class usable from all other class
      ... I create a class to manage configuration. ... For this, I have a constructor that create a dataset with all my parameters, ... And want to have a constructor (so impossible to have statict method) to ... retrieve all parameters. ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Nonce and Created Values. General Questions
      ... > I have set the replaydetection setting in my config file to false, ... > constructor of my usernamemanager implementation sets everything to base ... accepts the configuration node list: ... UsernameTokenManager, would be: ...
      (microsoft.public.dotnet.framework.webservices.enhancements)
    • ConfigurationManager and web.config and ASP.NET refresh curiosity
      ... appear to refresh within the request. ... Basically I added a new sqlCacheDependency using the configuration classes ... and then called the constructor of SqlCacheDependency with the corresponding ...
      (microsoft.public.dotnet.framework.aspnet)