| 1 | package Finance::SEC::EdgarData; | ||||||||||||||||||||
| 2 | 1 | ▶ | use XML::Bare; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use v5.10; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | require Exporter; | |||||||||||||||||||
| 9 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||
| 10 | 1 | our @EXPORT_OK = qw/ | |||||||||||||||||||
| 11 | set_user_agent | ||||||||||||||||||||
| 12 | get_filing_url | ||||||||||||||||||||
| 13 | get_xbrl_url | ||||||||||||||||||||
| 14 | get_filing_dates | ||||||||||||||||||||
| 15 | get_filing | ||||||||||||||||||||
| 16 | get_rss_url | ||||||||||||||||||||
| 17 | get_rss | ||||||||||||||||||||
| 18 | /; | ||||||||||||||||||||
| 19 | 1 | our @EXPORT = qw/ | |||||||||||||||||||
| 20 | set_user_agent | ||||||||||||||||||||
| 21 | get_filing_url | ||||||||||||||||||||
| 22 | get_xbrl_url | ||||||||||||||||||||
| 23 | get_filing_dates | ||||||||||||||||||||
| 24 | get_filing | ||||||||||||||||||||
| 25 | get_rss_url | ||||||||||||||||||||
| 26 | get_rss | ||||||||||||||||||||
| 27 | /; | ||||||||||||||||||||
| 28 | 1 | our $VERSION = '0.010021'; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 1 | my $BASE_URL = 'https://www.sec.gov'; | |||||||||||||||||||
| 31 | 1 | my $RSS_URL = "$BASE_URL/cgi-bin/browse-edgar?action=getcompany&CIK=%s&type=%s&dateb=&owner=exclude&count=500&output=atom"; | |||||||||||||||||||
| 32 | 1 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||
| 33 | 1 | my $agent = "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0"; | |||||||||||||||||||
| 34 | 1 | ▶ | $ua->agent($ENV{EDGAR_USER_AGENT} || $agent); | ||||||||||||||||||
|
Condition33%1/3
$ENV{'EDGAR_USER_AGENT'} || $agent
MC/DC0%0/2
$ENV{'EDGAR_USER_AGENT'} || $agent
$ENV{'EDGAR_USER_AGENT'}
$agent
Truth table33%1/3
A || B
A= $ENV{'EDGAR_USER_AGENT'}B= $agent
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 0 | ▶ | sub set_user_agent { | ||||||||||||||||||
|
Subroutine
set_user_agent: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 37 | 0 | my $g = shift; | |||||||||||||||||||
| 38 | 0 | $ua->agent($g); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | sub get_rss_url { | ||||||||||||||||||
|
Subroutine
get_rss_url: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 42 | 0 | my ($sym, $t) = @_; | |||||||||||||||||||
| 43 | 0 | my $url = sprintf($RSS_URL, $sym, $t); | |||||||||||||||||||
| 44 | 0 | return $url; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | ▶ | sub parse_rss { | ||||||||||||||||||
|
Subroutine
parse_rss: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 48 | 0 | my $xml = shift; | |||||||||||||||||||
| 49 | 0 | my $m = XML::Bare->new(text => $xml); | |||||||||||||||||||
| 50 | 0 | my $root = $m->parse(); | |||||||||||||||||||
| 51 | 0 | return $root; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | ▶ | sub get_rss { | ||||||||||||||||||
|
Subroutine
get_rss: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 55 | 0 | my $url = get_rss_url(@_); | |||||||||||||||||||
| 56 | 0 | my $res = $ua->get($url); | |||||||||||||||||||
| 57 | 0 | ▶ | if (!($res->is_success)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 0 | say STDERR $res->content; | |||||||||||||||||||
| 59 | 0 | return 0; | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | 0 | my $d = $res->content; | |||||||||||||||||||
| 62 | 0 | my $rss = parse_rss($d); | |||||||||||||||||||
| 63 | 0 | return $rss; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | ▶ | sub get_filing_dates { | ||||||||||||||||||
|
Subroutine
get_filing_dates: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 67 | 0 | my $rss = get_rss(@_); | |||||||||||||||||||
| 68 | 0 | my @dates = (); | |||||||||||||||||||
| 69 | 0 | for my $n (@{$rss->{feed}->{entry}}) { | |||||||||||||||||||
| 70 | 0 | push @dates, $n->{content}->{'filing-date'}->{value}; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | 0 | return @dates; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 0 | ▶ | sub get_filing_url { | ||||||||||||||||||
|
Subroutine
get_filing_url: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 76 | 0 | my ($sym, $t, $date) = @_; | |||||||||||||||||||
| 77 | 0 | my $rss = get_rss($sym, $t); | |||||||||||||||||||
| 78 | 0 | for my $n (@{$rss->{feed}->{entry}}) { | |||||||||||||||||||
| 79 | 0 | my $c = $n->{content}; | |||||||||||||||||||
| 80 | 0 | ▶ | if ($c->{'filing-date'}->{value} eq $date) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | 0 | return $c->{'filing-href'}->{value}; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | 0 | return 0; | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 0 | ▶ | sub get_xbrl_url { | ||||||||||||||||||
|
Subroutine
get_xbrl_url: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||
| 88 | 0 | my $link = shift; | |||||||||||||||||||
| 89 | 0 | my $res = $ua->get($link); | |||||||||||||||||||
| 90 | 0 | ▶ | return 0 unless $res->is_success; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | 0 | my $d = $res->content; | |||||||||||||||||||
| 92 | 0 | my $found = 0; | |||||||||||||||||||
| 93 | 0 | ▶ | while ($d =~ /<table.*?>(.*?)<\/table>/isg) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 0 | ▶ | if ($1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 0 | my $n = "<root>$1</root>"; | |||||||||||||||||||
| 96 | 0 | my $m = XML::Bare->new(text => $n); | |||||||||||||||||||
| 97 | 0 | my $root = $m->parse(); | |||||||||||||||||||
| 98 | 0 | for my $t (@{$root->{root}->{tr}}) { | |||||||||||||||||||
| 99 | 0 | for (@{$t->{td}}) { | |||||||||||||||||||
| 100 | 0 | ▶ | if ($found) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | 0 | return $BASE_URL . $_->{a}->{href}->{value}; | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | 0 | ▶ | next unless $_->{value}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | 0 | ▶ | if ($_->{value} =~ /XBRL INSTANCE DOCUMENT/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | 0 | $found = 1; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | 0 | return 0; | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 0 | ▶ | sub get_filing { | ||||||||||||||||||
|
Subroutine
get_filing: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 115 | 0 | my ($sym, $t, $date) = @_; | |||||||||||||||||||
| 116 | 0 | my $filing_url = get_filing_url($sym, $t, $date); | |||||||||||||||||||
| 117 | 0 | my $xbrl_url = get_xbrl_url($filing_url); | |||||||||||||||||||
| 118 | 0 | my $res = $ua->get($xbrl_url); | |||||||||||||||||||
| 119 | 0 | ▶ | return 0 unless $res->is_success; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 120 | 0 | my $d = $res->content; | |||||||||||||||||||
| 121 | 0 | my $m = XML::Bare->new(text => $d); | |||||||||||||||||||
| 122 | 0 | my $root = $m->parse(); | |||||||||||||||||||
| 123 | 0 | return $root; | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 1 | 1; | |||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||