Sha256: e0a000d8c3d01a77a771371953ca4ce0b762d2e268ef014e3a51bb0a549941f0

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

require 'perl/value'
require 'ffi'

class Perl::Value::Array
  class Av < FFI::Struct
    class Xnv_u < FFI::Union
      layout  :xnv_nv,        :long,
              :xgv_stash,     :pointer,
              :xpad_cop_seq,  :long,
              :xbm_s,         :long
    end

    layout  :xnv_u,     Xnv_u,
            :xav_fill,  :long,
            :xav_max,   :long

    def inspect
      "<#{self.class.name} @xav_fill=#{self[:xav_fill].inspect} @xav_max=#{self[:xav_max].inspect}>"
    end
  end

  def initialize(args)
    @perl = Perl.PL_curinterp
    @value = nil
    @array = nil
    @av = nil

    case args
    when Perl::Value::Scalar::SV
      @array = args[:sv_u][:svu_array]
      @av = Av.new(args[:sv_any])
    when nil
    else
      raise "Don't know how to handle #{args.class} (#{args.inspect})"
    end
  end

  def value
    return @value if @value
    if @array
      @value = @array.get_array_of_pointer(0, @av[:xav_fill]+1).map do |ptr|
        Perl::Value::Scalar.new(ptr)
      end
    else
      return nil
    end
  end

  def freeze!
    self.value.each { |v| v.freeze! }
    @array = nil
    @av = nil
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-perl-04.01.2011.2 lib/perl/value/array.rb
ruby-perl-04.01.2011.1 lib/perl/value/array.rb
ruby-perl-04.01.2011 lib/perl/value/array.rb
ruby-perl-0.99.15j lib/perl/value/array.rb