blessed coderefs

Discussion in 'Perl Misc' started by Rainer Weikusat, Jan 28, 2014.

  1. I've just encountered the first situation where the 'obvious solution'
    involves a blessed code references: I have a subsystem returning a
    closure which returns the names of PNG-files depicting QR-codes while
    creating the files as a side effect. I'd like to use a dedicated process
    for actual PNG generation so that this can be done in parallell with
    'other activities' of the same program. The ultimate output of this code
    is a PDF document containing the QR-code images, hence, it is necessary
    to wait until this coprocess has finished its work before generating the
    PDF. The simple solution to this seems to be to bless the returned coderef
    into a package whose DESTROY method waits for the corprocess.

    As soon as this is implemented, I will have used all kinds of 'ordinary
    references' available in Perl as objects at one point or another.
    Rainer Weikusat, Jan 28, 2014
    1. Advertisements

  2. I'm using Linux queued realtime signals for I/O notification in one
    program and the 'internal API' uses filehandles (glob references)
    blessed into a package/ class whose methods interact with the 'I/O
    notification subsystem' and enable/ disable O_ASYNC for the filehandle
    in question as desired which is 'sort of' an IO object. I also once
    accidentally caught a wild LVALUE and inspected it out of botancial
    curiosity[*] but I haven't found a use for these yet. Admittedly, I didn't
    use REF references (reference to a reference) as objects so far,
    either. I've never used formats for anything and I don't even know how
    to create a VSTRING reference.


    my $text = 'the day after';
    my $lv = \substr($text, 4, 3);
    $$lv = 'month';
    Rainer Weikusat, Jan 29, 2014
    1. Advertisements

  3. $ perl -e 'print ref \65.66.67'

    Here is one.

    Adrien BARREAU, Jan 29, 2014
  4. Since the glob 'came for free' (or 'as promotional giveaway') with the
    file handle, I'm using it to store information needed for using the
    object (in a rather contorted way by putting an arrayref into the scalar
    slot, which could be regared as a case of doing "what we always did so
    far" without considering if it actually makes sense in the given
    situation), namely, the file status flags and an additional flag word
    which records which I/O handlers are presently established for a given
    file handle so that O_ASYNC can be enabled/ disabled as needed whenever
    a handler is registered or removed.

    What were you using 'raw IO objects' for?
    Rainer Weikusat, Jan 30, 2014
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.