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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |