Subject: | Build problems and assumptions |
Hi Robert,
I tried installing this module and ran into some problems - I haven't done anything with modules from the RT:: namespace before so my environment was relatively virgin in this regard. I ran into the following problems:
* Path::Iterator::Rule was not a prereq
* I had no ~/.rtrc file and failed test didn't tell me what file it failed to find
So I figured I'd add the prereq, and allow for the config file to be a parameter at import time. However the config parsing and RT client construction were also happening at module load time so to support this I made them lazy.
As that's a new feature I bumped the version.
Now I can install the module without having ~/.rtrc in place, which is good, but now 00-load.t exercises slightly less code because the RT client is not constructed at import time. I'm not sure how to test the module more thorougly yet but thought I'd mention it.
I'd also like to suggest that making all warnings fatal is not futureproof:
http://www.modernperlbooks.com/mt/2014/01/fatal-warnings-are-a-ticking-time-bomb.html
Cheers for the code,
Andrew Kirkpatrick
Subject: | Path-Iterator-Rule-RT-0.01-to-0.02.diff |
diff -rubB Path-Iterator-Rule-RT-0.01/lib/Path/Iterator/Rule/RT.pm Path-Iterator-Rule-RT-0.02/lib/Path/Iterator/Rule/RT.pm
--- Path-Iterator-Rule-RT-0.01/lib/Path/Iterator/Rule/RT.pm 2014-02-27 11:33:25.374416305 +1030
+++ Path-Iterator-Rule-RT-0.02/lib/Path/Iterator/Rule/RT.pm 2014-02-27 11:22:03.253580715 +1030
@@ -8,19 +8,47 @@
use Error qw(:try);
use RT::Client::REST;
use RT::Client::REST::Ticket;
-my $config = parse_config_file( $ENV{HOME} . "/.rtrc" );
-my ( $username, $password, $server ) =
+
+my $config_file = $ENV{HOME} . "/.rtrc";
+
+my $config;
+
+my $rt;
+
+sub import {
+ my $package = shift;
+ if (@_ % 2) {
+ die "${package}::import expects an even number of arguments, if any";
+ }
+ my %args = @_;
+ if ($args{config_file}) {
+ $config_file = $args{config_file};
+ }
+}
+
+# lazy builder for the RT client in $rt and the configuration in $config
+sub rt {
+ unless ($rt) {
+ $config = parse_config_file( $config_file );
+
+ my ( $username, $password, $server ) =
( $config->{user}, $config->{passwd}, $config->{server} );
-my $rt = RT::Client::REST->new(
+
+ $rt = RT::Client::REST->new(
server => $server,
timeout => 30,
-);
-try {
+ );
+
+ try {
$rt->login( username => $username, password => $password );
-}
-catch Exception::Class::Base with {
+ }
+ catch Exception::Class::Base with {
die "problem logging in: ", shift->message;
-};
+ };
+ }
+
+ return $rt;
+}
Path::Iterator::Rule->add_helper(
"status" => sub {
@@ -58,14 +86,16 @@
=head1 VERSION
-Version 0.01
+Version 0.02
=cut
-our $VERSION = '0.01';
+our $VERSION = '0.02';
=head1 SYNOPSIS
+ use Path::Iterator::Rule::RT;
+
my $rule = Path::Iterator::Rule->new;
$rule->status("resolved");
for my $file ( $rule->all(@ARGV) ) {
@@ -96,7 +126,7 @@
my $ticket;
try {
$ticket = RT::Client::REST::Ticket->new(
- rt => $rt,
+ rt => rt(),
id => $id,
)->retrieve;
}
@@ -119,7 +149,7 @@
my $ticket;
try {
$ticket = RT::Client::REST::Ticket->new(
- rt => $rt,
+ rt => rt(),
id => $id,
)->retrieve;
}
@@ -153,7 +183,7 @@
my $query = "id=$id AND ";
$query .= $TicketSQL;
- my @ids = $rt->search(
+ my @ids = rt()->search(
type => 'ticket',
query => $query,
);
@@ -171,7 +201,7 @@
my ($file) = @_;
local $_;
- open( my $handle, '<', $file ) or die "$!";
+ open( my $handle, '<', $file ) or die "Error opening '$file' for reading: $!";
while (<$handle>) {
chomp;
@@ -189,6 +219,15 @@
return \%cfg;
}
+=head1 IMPORT
+
+By default this module searches for RT client configuration in F<$HOME/.rtrc>
+
+You can override the location by importing the module like so
+
+ use Path::Iterator::Rule::RT config_file => '/path/to/config/file';
+
+
=head1 AUTHOR
Robert Blackwell, C<< <robert at robertblackwell.com> >>
Only in Path-Iterator-Rule-RT-0.02: Makefile.old
diff -rubB Path-Iterator-Rule-RT-0.01/Makefile.PL Path-Iterator-Rule-RT-0.02/Makefile.PL
--- Path-Iterator-Rule-RT-0.01/Makefile.PL 2014-02-27 11:33:25.374416305 +1030
+++ Path-Iterator-Rule-RT-0.02/Makefile.PL 2014-02-27 11:18:18.406579349 +1030
@@ -6,6 +6,7 @@
'VERSION_FROM' => 'lib/Path/Iterator/Rule/RT.pm',
'PREREQ_PM' => {
'RT::Client::REST' => '0.45',
+ 'Path::Iterator::Rule' => '1.008',
'Test::More' => 0
},
'INSTALLDIRS' => 'site',
diff -rubB Path-Iterator-Rule-RT-0.01/META.json Path-Iterator-Rule-RT-0.02/META.json
--- Path-Iterator-Rule-RT-0.01/META.json 2014-02-27 11:33:25.374416305 +1030
+++ Path-Iterator-Rule-RT-0.02/META.json 2014-02-27 11:20:31.547619455 +1030
@@ -26,7 +26,8 @@
},
"runtime" : {
"requires" : {
- "RT::Client::REST" : "0.45"
+ "RT::Client::REST" : "0.45",
+ "Path::Iterator::Rule" : "1.008"
}
}
},
@@ -42,5 +43,5 @@
"http://www.perlfoundation.org/artistic_license_2_0"
]
},
- "version" : "0.01"
+ "version" : "0.02"
}
diff -rubB Path-Iterator-Rule-RT-0.01/META.yml Path-Iterator-Rule-RT-0.02/META.yml
--- Path-Iterator-Rule-RT-0.01/META.yml 2014-02-27 11:33:25.374416305 +1030
+++ Path-Iterator-Rule-RT-0.02/META.yml 2014-02-27 11:20:48.151250335 +1030
@@ -16,9 +16,10 @@
provides:
Path::Iterator::Rule::RT:
file: lib/Path/Iterator/Rule/RT.pm
- version: 0.01
+ version: 0.02
requires:
RT::Client::REST: 0.45
+ Path::Iterator::Rule: 1.008
resources:
license: http://www.perlfoundation.org/artistic_license_2_0
-version: 0.01
+version: 0.02