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
    1. Advertising

  2. Ben Morrow <> writes:
    > Quoth Rainer Weikusat <>:
    >> 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.

    >
    > IO? FORMAT? REGEXP? VSTRING? LVALUE? REF?


    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);
    print("$lv\n");
    $$lv = 'month';
    print("$text\n");
    Rainer Weikusat, Jan 29, 2014
    #2
    1. Advertising

  3. On 01/29/2014 04:21 PM, Rainer Weikusat wrote:

    > either. I've never used formats for anything and I don't even know how
    > to create a VSTRING reference.
    >


    $ perl -e 'print ref \65.66.67'
    VSTRING

    Here is one.


    Adrien.
    Adrien BARREAU, Jan 29, 2014
    #3
  4. Ben Morrow <> writes:
    > Quoth Rainer Weikusat <>:


    [...]

    >> 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.

    >
    > Oh no, that doesn't count :). I have actually used a bare IO (the thing
    > you get a reference to if you say *fh{IO} or Symbol::geniosym) as an
    > object in the past; when you don't need any other properties (or you're
    > doing them inside-out), there's no point lugging a whole glob around
    > when you just want the filehandle.


    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
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nick Marden
    Replies:
    0
    Views:
    1,055
    Nick Marden
    Jan 17, 2004
  2. Nick Marden
    Replies:
    1
    Views:
    124
    Ben Morrow
    Jan 20, 2004
  3. Vetle Roeim

    Threads and shared blessed references

    Vetle Roeim, Jun 9, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    155
    Vetle Roeim
    Jun 9, 2004
  4. sbk

    pulling apart a blessed hash

    sbk, Jan 26, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    92
    Gary E. Ansok
    Jan 26, 2005
  5. Replies:
    18
    Views:
    212
    Joe Smith
    Oct 5, 2005
Loading...

Share This Page