Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

There's a lot of stuff here and I can't answer it all as I get ready for work so I'll rush through this.

The speed penalty is most at compile time. There's actually not much of a runtime speed penalty if code without this module attempts the same level of validation. If you don't mind the compile time hit, you're probably OK. In a persistent environment (such as mod_perl) you may never notice. Caveat: I haven't benchmarked this, so take what I say with a grain of salt. I was looking for programmer efficiency rather than CPU efficiency.

It should have no impact on caller because internally it uses goto to subvert the call stack. In this respect, it's even better than some hand-rolled code. However, I didn't write tests for this. I should do that. And can you give other introspective examples you'd like to see tested?

As for the code snippet you tested, yes it will handle that, if you use 'strict' mode.

use Sub::Signatures 'strict'; sub foo (CGI $cgi) {...} sub foo (CGI $cgi, ARRAY $arr) {...}

In 'strict' mode, it considers the types of variables. That would actually work in 'loose' mode, but only because each subroutine has a different number of variables. Naturally, that would be more bug-prone. I wonder if I should have made 'strict' the default instead of 'loose'?

I used ref instead of Scalar::Util on the "simplest thing that could possibly work" principle. If you can give me a clear code snippet showing why ref is inferior (or point me to a resource.) I'll happily change it. (Update: Of course, I seem to recall some of the issues you mention. Hmm, I don't think I have a choice but to change it.)

The problem with more than one package per file is a combination of my code and how Filter::Simple works. It's very important that I know my calling package when setting argument lists with the subroutines so I determine this in &import. However, Filter::Simple keeps scanning through the code and cheerfully skips past package declarations, thus meaning I could alter subs in the wrong package. I thought about trying to parse out the the declarations and it didn't seem too hard, but Perl has so many odd corners that I thought there would be a good chance of missing something. As a result, I opted to keep it simple for my initial release.

I don't use prototypes because they're useless with methods and I wanted to limit the differences between using functions and methods. Right now they behave almost identically. What I didn't want was having to constantly respond to the following bug report:

sub foo(@bar) {...} # works fine sub foo($self, @bar) {...} # how would this work?

And I didn't use attributes because even though I knew I could get something like signatures working, the real problem I wanted to transparently solve was signature-based multi-method dispatch. I don't know if that's possible with using attributes and a relatively straightforward syntax.

Cheers,
Ovid

New address of my CGI Course.


In reply to Re^2: Use method/function signatures with Perl by Ovid
in thread Use method/function signatures with Perl by Ovid

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (5)
    As of 2014-08-22 01:10 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (145 votes), past polls