Hello dear Monks, I would like to ask a simple question to your unlimited Monk knowledge. In recent days I've been reading Shared Memory modules code but all of the sudden I encountered some 'unpack' syntax that was very unfamiliar to me:

package IPC::SharedMem; use IPC::SysV qw(IPC_STAT IPC_RMID shmat shmdt memread memwrite); use strict; use vars qw($VERSION); use Carp; $VERSION = do { my @r = '$Snapshot: /IPC-SysV/2.01 $' =~ /(\d+\.\d+(?: +_\d+)?)/; @r ? $r[0] : '9.99' }; $VERSION = eval $VERSION; # Figure out if we have support for native sized types my $N = do { my $foo = eval { pack "L!", 0 }; $@ ? '' : '!' }; { package IPC::SharedMem::stat; use Class::Struct qw(struct); struct 'IPC::SharedMem::stat' => [ uid => '$', gid => '$', cuid => '$', cgid => '$', mode => '$', segsz => '$', lpid => '$', cpid => '$', nattch => '$', atime => '$', dtime => '$', ctime => '$', ]; } sub new { @_ == 4 or croak 'IPC::SharedMem->new(KEY, SIZE, FLAGS)'; my($class, $key, $size, $flags) = @_; my $id = shmget $key, $size, $flags; return undef unless defined $id; bless { _id => $id, _addr => undef, _isrm => 0 }, $class } sub id { my $self = shift; $self->{_id}; } sub addr { my $self = shift; $self->{_addr}; } sub stat { my $self = shift; my $data = ''; shmctl $self->id, IPC_STAT, $data or return undef; IPC::SharedMem::stat->new->unpack($data); }

What I can not figure out is the line of code that has 'unpack' in it. If any Monk could share his/her wisdom to this apprentice would be great. My initial guess is that somehow 'unpack' is a method of the class IPC::SharedMem::stat but I may also think that it is actually the core unpack function that somehow is being used as a method


In reply to IPC::SharedMem::stat using Class::Struct by sprinter

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.