Skip to content

Instantly share code, notes, and snippets.

@Tux
Created May 3, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tux/12387de2febd2eda1efc to your computer and use it in GitHub Desktop.
Save Tux/12387de2febd2eda1efc to your computer and use it in GitHub Desktop.
class CSV::Row is Iterable does Positional {
has Text::CSV $.csv;
has CSV::Field @.fields is rw;
multi method new (@f) {
@!fields = @f.map ({ CSV::Field.new (*) });
}
method Str { $!csv ?? $!csv.string (@!fields) !! Str; }
method iterator { [ @.fields ].iterator; }
method hash { my @h = $!csv.column_names or return;
hash @h Z @!fields;
}
method AT-POS (int $i) { @!fields[$i]; }
multi method push (CSV::Field $f) { @!fields.push: $f; }
multi method push (Cool $f) { @!fields.push: CSV::Field.new ($f); }
# multi method push (CSV::Row $r) { for ($r.fields) -> $f { @!fields.push: $f; }}
multi method push (CSV::Row $r) { @!fields.push: @$r.fields; }}
method pop returns CSV::Field { @!fields.pop; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment