| 1 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package RT::ClientX::GrabBugs; | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | $RT::ClientX::GrabBugs::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||
| 10 | 1 | $RT::ClientX::GrabBugs::VERSION = '0.005'; | |||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Try::Tiny qw(try catch finally); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Types::Standard qw(-types); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Getopt::ArgvFile qw(argvFile); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Getopt::Long qw(GetOptionsFromArray); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use RDF::Trine qw(literal blank iri); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use RT::Client::REST qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use RT::Client::REST::Queue qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use Cwd qw(cwd); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Path::FindDev qw(find_dev); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Digest::SHA1 qw(sha1_hex); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use RDF::Trine::Namespace qw/rdf rdfs owl xsd/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 1 | my $dbug = RDF::Trine::Namespace->new('http://ontologi.es/doap-bugs#'); | |||||||||||||||||||||||||||
| 29 | 1 | my $dc = RDF::Trine::Namespace->new('http://purl.org/dc/terms/'); | |||||||||||||||||||||||||||
| 30 | 1 | my $doap = RDF::Trine::Namespace->new('http://usefulinc.com/ns/doap#'); | |||||||||||||||||||||||||||
| 31 | 1 | my $foaf = RDF::Trine::Namespace->new('http://xmlns.com/foaf/0.1/'); | |||||||||||||||||||||||||||
| 32 | 1 | my $status = RDF::Trine::Namespace->new('http://purl.org/NET/cpan-uri/rt/status/'); | |||||||||||||||||||||||||||
| 33 | 1 | my $prio = RDF::Trine::Namespace->new('http://purl.org/NET/cpan-uri/rt/priority/'); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | has [qw/user pass/] => ( | |||||||||||||||||||||||||||
| 36 | is => 'ro', | ||||||||||||||||||||||||||||
| 37 | isa => Str, | ||||||||||||||||||||||||||||
| 38 | required => 1, | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | has server => ( | |||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||
| 43 | isa => Str, | ||||||||||||||||||||||||||||
| 44 | default => 'https://rt.cpan.org', | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | has project_uri => ( | |||||||||||||||||||||||||||
| 48 | is => 'ro', | ||||||||||||||||||||||||||||
| 49 | isa => Str, | ||||||||||||||||||||||||||||
| 50 | lazy => 1, | ||||||||||||||||||||||||||||
| 51 | builder => '_build_project_uri', | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | has queue => ( | |||||||||||||||||||||||||||
| 55 | is => 'ro', | ||||||||||||||||||||||||||||
| 56 | isa => Str, | ||||||||||||||||||||||||||||
| 57 | lazy => 1, | ||||||||||||||||||||||||||||
| 58 | builder => '_build_queue', | ||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | has queue_model => ( | |||||||||||||||||||||||||||
| 62 | is => 'ro', | ||||||||||||||||||||||||||||
| 63 | isa => InstanceOf['RDF::Trine::Model'], | ||||||||||||||||||||||||||||
| 64 | lazy => 1, | ||||||||||||||||||||||||||||
| 65 | builder => '_build_queue_model', | ||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | has dest => ( | ||||||||||||||||||||||||||||
| 69 | is => 'ro', | ||||||||||||||||||||||||||||
| 70 | isa => Str | InstanceOf['Path::Tiny'], | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | default => sub { find_dev(cwd)->child('meta/rt-bugs.ttl') }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 72 | 1 | ); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub main | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
main: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | argvFile( | |||||||||||||||||||||||||||
| 79 | array => \@argv, | ||||||||||||||||||||||||||||
| 80 | startupFilename => '.rt-grabbugs', | ||||||||||||||||||||||||||||
| 81 | current => 1, | ||||||||||||||||||||||||||||
| 82 | home => 1, | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | my %opts; | |||||||||||||||||||||||||||
| 86 | 0 | GetOptionsFromArray( | |||||||||||||||||||||||||||
| 87 | \@argv, | ||||||||||||||||||||||||||||
| 88 | \%opts, | ||||||||||||||||||||||||||||
| 89 | qw/ | ||||||||||||||||||||||||||||
| 90 | queue=s | ||||||||||||||||||||||||||||
| 91 | dest=s | ||||||||||||||||||||||||||||
| 92 | user=s | ||||||||||||||||||||||||||||
| 93 | pass=s | ||||||||||||||||||||||||||||
| 94 | server=s | ||||||||||||||||||||||||||||
| 95 | project_uri=s | ||||||||||||||||||||||||||||
| 96 | /, | ||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | $class->new(%opts)->process; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | sub _build_queue | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_build_queue: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 104 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | 0 | my $root = find_dev(cwd); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | my $ini = $root->child('dist.ini'); | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($ini) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||
| 110 | 0 | my @ini = grep /^;;/, do { my $fh = $ini->openr; <$fh> }; | |||||||||||||||||||||||||||
| 111 | 0 | chomp @ini; | |||||||||||||||||||||||||||
| 112 | my %config = map { | ||||||||||||||||||||||||||||
| 113 | 0 | s/(?:^;;\s*)|(?:\s*$)//g; | |||||||||||||||||||||||||||
| 114 | 0 | my ($key, $value) = split /\s*=\s*/, $_, 2; | |||||||||||||||||||||||||||
| 115 | 0 | $key => scalar(eval($value)); | |||||||||||||||||||||||||||
| 116 | } @ini; | ||||||||||||||||||||||||||||
| 117 | 0 | ▶ | return $config{name} if $config{name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | confess "Unable to determine RT queue. Please specify manually."; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | sub _build_project_uri | ||||||||||||||||||||||||||||
| 124 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_build_project_uri: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 125 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 126 | 0 | sprintf('http://purl.org/NET/cpan-uri/dist/%s/project', $self->queue); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | sub _build_queue_model | ||||||||||||||||||||||||||||
| 130 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_build_queue_model: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 131 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 132 | 0 | my $model = RDF::Trine::Model->new; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | warn sprintf "Logging in to %s\n", $self->server; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | my $rt; | |||||||||||||||||||||||||||
| 137 | try | ||||||||||||||||||||||||||||
| 138 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 139 | 0 | $rt = RT::Client::REST->new( | |||||||||||||||||||||||||||
| 140 | server => $self->server, | ||||||||||||||||||||||||||||
| 141 | timeout => 60, | ||||||||||||||||||||||||||||
| 142 | ); | ||||||||||||||||||||||||||||
| 143 | 0 | push @{ $rt->_ua->{requests_redirectable} }, 'POST'; | |||||||||||||||||||||||||||
| 144 | 0 | $rt->login( | |||||||||||||||||||||||||||
| 145 | username => $self->user, | ||||||||||||||||||||||||||||
| 146 | password => $self->pass, | ||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | catch | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 151 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||
| 152 | 0 | die Data::Dumper::Dumper($_); | |||||||||||||||||||||||||||
| 153 | 0 | }; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | warn sprintf "Retrieving queue for %s\n", $self->queue; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | my $queue = RT::Client::REST::Queue->new( | |||||||||||||||||||||||||||
| 158 | rt => $rt, | ||||||||||||||||||||||||||||
| 159 | id => $self->queue, | ||||||||||||||||||||||||||||
| 160 | )->retrieve; | ||||||||||||||||||||||||||||
| 161 | 0 | my $tickets = $queue->tickets->get_iterator; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | while (my $ticket = $tickets->()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||
| 165 | 0 | $self->_process_ticket($model, $queue, $ticket); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | return $model; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 1 | my %EMAIL; | |||||||||||||||||||||||||||
| 172 | sub _process_ticket | ||||||||||||||||||||||||||||
| 173 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_process_ticket: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 174 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 175 | 0 | my ($model, $queue, $ticket) = @_; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | warn sprintf("Processing RT#%d\n", $ticket->id); | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | my $P = iri $self->project_uri; | |||||||||||||||||||||||||||
| 180 | 0 | my $T = iri sprintf('http://purl.org/NET/cpan-uri/rt/ticket/%d', $ticket->id); | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | $model->add_statement($_) for ( | |||||||||||||||||||||||||||
| 183 | RDF::Trine::Statement->new($P, $dbug->issue, $T), | ||||||||||||||||||||||||||||
| 184 | RDF::Trine::Statement->new($T, $rdf->type, $dbug->Issue), | ||||||||||||||||||||||||||||
| 185 | RDF::Trine::Statement->new($T, $dbug->id, literal($ticket->id)), | ||||||||||||||||||||||||||||
| 186 | RDF::Trine::Statement->new($T, $dbug->page, iri sprintf('https://rt.cpan.org/Public/Bug/Display.html?id=%d', $ticket->id)), | ||||||||||||||||||||||||||||
| 187 | 0 | RDF::Trine::Statement->new($T, $dbug->status, $status->${\ $ticket->status }), | |||||||||||||||||||||||||||
| 188 | RDF::Trine::Statement->new($T, $dc->created, literal($ticket->created, undef, $xsd->dateTime)), | ||||||||||||||||||||||||||||
| 189 | RDF::Trine::Statement->new($T, $rdfs->label, literal($ticket->subject)), | ||||||||||||||||||||||||||||
| 190 | ); | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 0 | for my $email ($ticket->requestors) { | |||||||||||||||||||||||||||
| 193 | my $R = ($email =~ /\A(\w+)\@cpan.org\z/i) | ||||||||||||||||||||||||||||
| 194 | ? iri(sprintf 'http://purl.org/NET/cpan-uri/person/%s', uc $1) | ||||||||||||||||||||||||||||
| 195 | 0 | ▶ | : ( $EMAIL{$email} ||= blank() ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$EMAIL{$email} ||= blank()
MC/DC0%0/2
$EMAIL{$email} ||= blank()
$EMAIL{$email}
blank()
Truth table0%0/3
A ||= B
A= $EMAIL{$email}B= blank()
| |||||||||||||||||||||||||||||
| 196 | 0 | $model->add_statement($_) for ( | |||||||||||||||||||||||||||
| 197 | RDF::Trine::Statement->new($T, $dc->reporter, $R), | ||||||||||||||||||||||||||||
| 198 | RDF::Trine::Statement->new($R, $rdf->type, $foaf->Agent), | ||||||||||||||||||||||||||||
| 199 | RDF::Trine::Statement->new($R, $foaf->mbox_sha1sum, literal(sha1_hex(sprintf('mailto:%s', $email)))), | ||||||||||||||||||||||||||||
| 200 | ); | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 202 | 0 | RDF::Trine::Statement->new($R, $foaf->mbox, iri sprintf('mailto:%s', $email)), | |||||||||||||||||||||||||||
| 203 | 0 | }; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | sub process | ||||||||||||||||||||||||||||
| 208 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
process: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 209 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | my $model = $self->queue_model; | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my $ser = eval { require RDF::TrineX::Serializer::MockTurtleSoup } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | ? 'RDF::TrineX::Serializer::MockTurtleSoup' | ||||||||||||||||||||||||||||
| 215 | : 'RDF::Trine::Serializer::Turtle'; | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 0 | warn sprintf("Writing to %s using %s\n", $self->dest, $ser); | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 0 | open my $fh, '>:encoding(UTF-8)', $self->dest; | |||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | $ser->new(namespaces => { | |||||||||||||||||||||||||||
| 222 | dbug => 'http://ontologi.es/doap-bugs#', | ||||||||||||||||||||||||||||
| 223 | dc => 'http://purl.org/dc/terms/', | ||||||||||||||||||||||||||||
| 224 | doap => 'http://usefulinc.com/ns/doap#', | ||||||||||||||||||||||||||||
| 225 | foaf => 'http://xmlns.com/foaf/0.1/', | ||||||||||||||||||||||||||||
| 226 | rdfs => 'http://www.w3.org/2000/01/rdf-schema#', | ||||||||||||||||||||||||||||
| 227 | rt => 'http://purl.org/NET/cpan-uri/rt/ticket/', | ||||||||||||||||||||||||||||
| 228 | status => 'http://purl.org/NET/cpan-uri/rt/status/', | ||||||||||||||||||||||||||||
| 229 | prio => 'http://purl.org/NET/cpan-uri/rt/priority/', | ||||||||||||||||||||||||||||
| 230 | xsd => 'http://www.w3.org/2001/XMLSchema#', | ||||||||||||||||||||||||||||
| 231 | })->serialize_model_to_file($fh, $model); | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | $self; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 1 | __PACKAGE__ | |||||||||||||||||||||||||||
| 237 | __END__ | ||||||||||||||||||||||||||||