App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Suffix/NZ.pm  view on Meta::CPAN


    # Dividends not in NZD shown just as note.
    # Can have AUD for dual-listed Aust/NZ shares, eg. DOW.AX = DOW.NZ
    # In the past had some GBP.
    my $note;
    my $currency = $href->{'currencyCode'} // '';
    if ($currency ne 'NZD') {
      if ($imput ne '' && $imput != 0) {
        $note = "$amount + $imput $currency";
      } else {
        $note = "$amount $currency";
      }
      $note = App::Chart::collapse_whitespace ($note);
      $amount = undef;
      $imput = undef;
    }

    push @dividends, { symbol     => $symbol,
                       ex_date    => $ex_date,
                       pay_date   => $pay_date,
                       amount     => $amount,
                       imputation => $imput,
                       note       => $note,
                     };
  }
  my $count = scalar(@dividends);
  App::Chart::Download::verbose_message ("NZX dividends total $count found");
  return $h;
}

sub dividend_parse {
  my ($symbol, $ex_date,$pay_date,$amount, $currency,$imput) = @_;
  ### NZ dividend_parse(): @_

  # leading and trailing whitespace

  foreach ($amount, $imput) {
    # eg. "3.900c" with c for cents, or latin-1 0xA2 cents symbol
    if (s/ *[c\xA2]$//) {
      $_ =  ($_);
    }
    # discard trailing zeros, when a whole number of cents
    $_ = App::Chart::Download::trim_decimals ($_, 2);
  }

  # foreign like AUD or GBP turned into merely a note

  return ;
}

#------------------------------------------------------------------------------

# (String quoting for parsing of <script> in HTML to get crumb.)
# undo javascript string backslash quoting in STR, per
#
#     https://developer.mozilla.org/en/JavaScript/Guide/Values,_Variables,_and_Literals#String_Literals
#
# Encode::JavaScript::UCS does \u, but not the rest
#
# cf Java as such not quite the same:
#   unicode: http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#100850
#   strings: http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#101089
#
my %javascript_backslash = ('b' => "\b",   # backspace
                            'f' => "\f",   # formfeed
                            'n' => "\n",   # newline
                            'r' => "\r",
                            't' => "\t",   # tab
                            'v' => "\013", # vertical tab
                           );
sub javascript_string_unquote {
  my ($str) = @_;
  $str =~ s{\\(?:
              ((?:[0-3]?[0-7])?[0-7]) # $1 \377 octal latin-1
            |x([0-9a-fA-F]{2})        # $2 \xFF hex latin-1
            |u([0-9a-fA-F]{4})        # $3 \uFFFF hex unicode
            |(.)                      # $4 \n etc escapes
            )
         }{
           (defined $1 ? chr(oct($1))
            : defined $4 ? ($javascript_backslash{$4} || $4)
            : chr(hex($2||$3)))   # \x,\u hex
         }egx;
  return $str;
}


#------------------------------------------------------------------------------

1;
__END__



( run in 2.599 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )