Professional Web Applications Themes

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

ed <coo_t2-NO-LIKE-SPAM> 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 ...

  1. #1

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

    ed <coo_t2-NO-LIKE-SPAM> 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. #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]tiltonjerols.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

  3. #3

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

    ed <coo_t2-NO-LIKE-SPAM> 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]tadmcaugustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  4. #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]tadmcaugustmail.com[/email] (Tad
    McClellan) wrote:
    >ed <coo_t2-NO-LIKE-SPAM> 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

Similar Threads

  1. #25441 [Opn->Csd]: public properties of parent class not accessible
    By sniper@php.net in forum PHP Development
    Replies: 0
    Last Post: November 18th, 10:02 PM
  2. #23038 [Com]: PHP does not detect parent class inside child class' constructor
    By hewei at ied dot org dot cn in forum PHP Development
    Replies: 0
    Last Post: August 6th, 02:58 AM
  3. Extracting a parent class
    By Hal E. Fulton in forum Ruby
    Replies: 9
    Last Post: August 1st, 04:10 AM
  4. Passing a method block to a parent class
    By Eric Anderson in forum Ruby
    Replies: 3
    Last Post: July 27th, 09:41 PM
  5. HowTo get a Viewstate Value from my Parent Class?
    By Andreas Klemt in forum ASP.NET General
    Replies: 0
    Last Post: July 14th, 10:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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