blessed coderefs

R

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

Rainer Weikusat

Ben Morrow said:
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");
 
A

Adrien BARREAU

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

Rainer Weikusat

Ben Morrow said:
Quoth Rainer Weikusat <[email protected]>:
[...]
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?
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top