Main Content

Introspecion in Perl 6

Archive - Originally posted on "The Horse's Mouth" - 2016-01-02 21:41:17 - Graham Ellis

Perl 6 provides introspection - that's the ability for its object to be able to report on methods, attributes and inheritances.

And if you run Perl6 without an input file, it goes into a read - interpret - run cycle with each line you type in, rather like Python, Ruby and Tcl do. So we can experiment easily with that introspection.

  WomanWithCat:jan16 grahamellis$ perl6
  > "...".^methods
  (BUILD Int Num chomp chop pred succ simplematch match ords samecase
  samemark samespace word-by-word trim-leading trim-trailing trim
  encode NFC NFD NFKC NFKD wordcase trans indent codes chars uc
  lc tc fc tclc flip ord WHY WHICH Bool Str Stringy DUMP ACCEPTS
  Numeric gist perl comb subst-mutate subst lines split words)
  >


  WomanWithCat:jan16 grahamellis$ perl6
  > my $v = 4;
  4
  > $v.^methods
  (Int Num Rat FatRat abs Bridge chr sqrt base polymod expmod is-prime
  floor ceiling round lsb msb narrow Range sign sin tan cotan acosech
  conj atan2 cosec pred asec acotan cosh acos acosec sech unpolar
  log10 atanh log exp acosh truncate sinh tanh acotanh Real sec
  isNaN succ rand asin cos cis cosech asech roots Complex cotanh
  asinh atan WHICH new perl Bool Str gist ACCEPTS DUMP Numeric)
  >