getting name of class and/or parent class that object belongs to

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Re: getting name of class and/or parent class that object belongs to

    ed <coo_t2-NO-LIKE-SPAM@yahoo.com> wrote:

    :
    : Hey all. I'd like to convert some PHP code to Perl, but I'm not sure
    : how to do it in Perl.
    : The PHP method takes an argument which might be an error object.
    :
    : I have to figure the following about the argument:
    : 1. If it's an object
    : 2. If it's of class "apperror"
    : 3. Alternatively if it's a subclass of "apperror"

    You can satisfy all three requirements at once.

    if( UNIVERSAL::isa($foo, 'apperror') ) {
    print '$foo is an apperror object';
    }

    : The only part of the code below I know how to convert is the:
    : get_class($e)=='apperror'
    :
    : In Perl I'd do:
    : (ref $e)=='apperror'
    :
    : Right?

    Nope.

    The '==' operator compares in numerical context.
    The 'eq' operator compares in string context.

    You could do

    if( ref($e) eq 'apperror' ) {
    ....
    }

    But that would check only whether $e is blessed into the apperror
    class, not whether $e inherits from the apperror class.

    Jay Tilton Guest

  2. Similar Questions and Discussions

    1. Reference to parent in license-enabled class constructor
      I am using LicenseProvider to enable licensing for a web user control using C#. My license consists of a signed XML .lic file. Among other things,...
    2. #23038 [Com]: PHP does not detect parent class inside child class' constructor
      ID: 23038 Comment by: hewei at ied dot org dot cn Reported By: black at sunshine dot krneki dot org Status: ...
    3. Extracting a parent class
      ----- Original Message ----- From: "Michael Garriss" <mgarriss@earthlink.net> To: "ruby-talk ML" <ruby-talk@ruby-lang.org> Sent: Thursday, July...
    4. Passing a method block to a parent class
      If I have **** CODE **** class A def method1( argument ) yield( argument ) end end
    5. HowTo get a Viewstate Value from my Parent Class?
      Hello, lets say I want to get from my Parent Class the viewstate("userID") How can I access this an get the value? Thanks for any help Andreas
  3. #2

    Default Re: getting name of class and/or parent class that object belongs to

    On Tue, 22 Jul 2003 22:14:30 GMT, [email]tiltonj@erols.com[/email] (Jay Tilton)
    wrote:
    >
    >You can satisfy all three requirements at once.
    >
    > if( UNIVERSAL::isa($foo, 'apperror') ) {
    > print '$foo is an apperror object';
    > }
    >
    Thanks.
    I figured there was an easy way to do it.
    Now I'm off to [url]http://www.perldoc.com/perl5.8.0/lib/UNIVERSAL.html[/url]
    to find out _why_ it works :)

    --ed

    ed Guest

  4. #3

    Default Re: getting name of class and/or parent class that object belongs to

    ed <coo_t2-NO-LIKE-SPAM@yahoo.com> wrote:
    > Now I'm off to [url]http://www.perldoc.com/perl5.8.0/lib/UNIVERSAL.html[/url]

    Errr, why go way over there for it when it is already on
    your very own hard disk?



    Type:

    perldoc UNIVERSAL

    at a command line.


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  5. #4

    Default Re: getting name of class and/or parent class that object belongs to

    On Tue, 22 Jul 2003 19:12:22 -0500, [email]tadmc@augustmail.com[/email] (Tad
    McClellan) wrote:
    >ed <coo_t2-NO-LIKE-SPAM@yahoo.com> wrote:
    >
    >> Now I'm off to [url]http://www.perldoc.com/perl5.8.0/lib/UNIVERSAL.html[/url]
    >
    >
    >Errr, why go way over there for it when it is already on
    >your very own hard disk?
    >
    >
    >
    >Type:
    >
    > perldoc UNIVERSAL
    >
    >at a command line.

    I'm using activestate perl on windows and for some reason perldoc
    doesn't work from the command line. However the distro does come with
    a windows version of the docs.
    I'm gonna have to reinstall or upgrade and see if I can get perldoc
    working from the command line.

    --ed
    ed Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139