Codebase list liblog-report-perl / 0d52d56
distribution Log-Report-0.27.tar.gz Mark Overmeer authored 13 years ago Mark Overmeer committed 6 years ago
4 changed file(s) with 65 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
00
11 ==== version history of Log::Report
2
3 version 0.27: Fri May 28 15:37:44 CEST 2010
4
5 Fixes:
6
7 - turn autoflush on for FILE dispatcher. Found by [Robin V.]
8
9 - Test::More 0.95_01 changes is() w.r.t. overloading... broken
10 tests. rt.cpan.org#57703 [Slaven Rezic]
211
312 version 0.26: Mon Feb 15 10:08:23 CET 2010
413
11
22 use 5.008;
33
4 my $version = '0.26';
4 my $version = '0.27';
55
66 my %prereq =
77 ( Test::More => 0.86
4747 =section Constructors
4848
4949 =c_method new TYPE, NAME, OPTIONS
50 =requires to FILENAME|FILEHANDLE|FILE-OBJECT
51 You can either specify a FILENAME, which is opened in append mode, or
52 any kind of handle or object which accepts supports C<print()>.
50
51 =requires to FILENAME|FILEHANDLE|OBJECT
52 You can either specify a FILENAME, which is opened in append mode with
53 autoflush on. Or pass any kind of FILE-HANDLE or some OBJECT which
54 implements a C<print()> method. You probably want to have autoflush
55 enabled on your FILE-HANDLES.
56
5357 When cleaning-up the dispatcher, the file will only be closed in case
5458 of a FILENAME.
5559
8791 { $self->{filename} = $to;
8892 my $binmode = $args->{replace} ? '>' : '>>';
8993
90 $self->{output} = IO::File->new($to, $binmode)
94 my $f = $self->{output} = IO::File->new($to, $binmode)
9195 or fault __x"cannot write log into {file} with {binmode}"
9296 , binmode => $binmode, file => $to;
97 $f->autoflush;
9398
9499 trace "opened dispatcher $name to $to with $binmode";
95100 }
1010 use Scalar::Util qw/reftype/;
1111
1212 ### examples from Log::Report::Message and more
13 # Check overloading
14
15 sub ol_is($$;$)
16 { # since Test::More 0.95_01, is() does not stringify its arguments.
17 # This means that overloading does not quick in. How to test
18 # overloading now?
19 my ($f, $s, $comment) = @_;
20 overload::Overloaded($f) || overload::Overloaded($s)
21 or die "both not overloaded, in '$f' and '$s'";
22 is("$f", "$s", $comment);
23 }
1324
1425 my $a = __"Hello";
1526 ok(defined $a);
1627 is(ref $a, 'Log::Report::Message');
1728 is(reftype $a, 'HASH');
18 is(__"Hello World", 'Hello World');
19 is(__"Hello World {a}", 'Hello World {a}');
20 is(__('Hello World {a}'), 'Hello World {a}');
29 ol_is(__"Hello World", 'Hello World');
30 ol_is(__"Hello World {a}", 'Hello World {a}');
31 ol_is(__('Hello World {a}'), 'Hello World {a}');
2132
2233 my $c = __x"Hello";
2334 ok(defined $c);
2435 is(ref $c, 'Log::Report::Message');
2536 is(reftype $c, 'HASH');
26 is(__x("Hello World", a => 42), 'Hello World');
27 is(__x("Hello World {a}", a => 42), 'Hello World 42');
28 is((__x"Hello World {a}", a => 42), 'Hello World 42');
29 is((__x "Hello World {a}", a => 42), 'Hello World 42');
30 is((__x "{a}{a}{a}", a => 42), '424242');
37 ol_is(__x("Hello World", a => 42), 'Hello World');
38 ol_is(__x("Hello World {a}", a => 42), 'Hello World 42');
39 ol_is((__x"Hello World {a}", a => 42), 'Hello World 42');
40 ol_is((__x "Hello World {a}", a => 42), 'Hello World 42');
41 ol_is((__x "{a}{a}{a}", a => 42), '424242');
3142
3243 my $d = __n"Hello","World",3;
3344 ok(defined $d);
3445 is(ref $d, 'Log::Report::Message');
3546 is(reftype $d, 'HASH');
36 is(__n("Hello", "World", 1), 'Hello');
37 is(__n("Hello", "World", 0), 'World');
38 is(__n("Hello", "World", 2), 'World');
47 ol_is(__n("Hello", "World", 1), 'Hello');
48 ol_is(__n("Hello", "World", 0), 'World');
49 ol_is(__n("Hello", "World", 2), 'World');
3950
4051 my $e = __nx"Hello","World",3,a=>42;
4152 ok(defined $e);
4253 is(ref $e, 'Log::Report::Message');
4354 is(reftype $e, 'HASH');
44 is(__nx("Hel{a}lo", "Wor{a}ld", 1,a=>42), 'Hel42lo');
45 is(__nx("Hel{a}lo", "Wor{a}ld", 0,a=>42), 'Wor42ld');
46 is(__nx("Hel{a}lo", "Wor{a}ld", 2,a=>42), 'Wor42ld');
47 is(__xn("Hel{a}lo", "Wor{a}ld", 2,a=>42), 'Wor42ld');
55 ol_is(__nx("Hel{a}lo", "Wor{a}ld", 1,a=>42), 'Hel42lo');
56 ol_is(__nx("Hel{a}lo", "Wor{a}ld", 0,a=>42), 'Wor42ld');
57 ol_is(__nx("Hel{a}lo", "Wor{a}ld", 2,a=>42), 'Wor42ld');
58 ol_is(__xn("Hel{a}lo", "Wor{a}ld", 2,a=>42), 'Wor42ld');
4859
4960 my $e1 = 1;
50 is((__nx "one", "more", $e1++), "one");
51 is((__nx "one", "more", $e1), "more");
61 ol_is((__nx "one", "more", $e1++), "one");
62 ol_is((__nx "one", "more", $e1), "more");
5263 my @files = 'monkey';
5364 my $nr_files = @files;
54 is((__nx "one file", "{_count} files", $nr_files), 'one file');
55 is((__nx "one file", "{_count} files", @files), 'one file');
65 ol_is((__nx "one file", "{_count} files", $nr_files), 'one file');
66 ol_is((__nx "one file", "{_count} files", @files), 'one file');
5667 push @files, 'donkey';
5768 $nr_files = @files;
58 is((__nx "one file", "{_count} files", $nr_files), '2 files');
59 is((__nx "one file", "{_count} files", @files), '2 files');
69 ol_is((__nx "one file", "{_count} files", $nr_files), '2 files');
70 ol_is((__nx "one file", "{_count} files", @files), '2 files');
6071
6172 my $f = N__"Hi";
6273 ok(defined $f);
7485 # Use _count directly
7586 #
7687
77 is(__nx("single {_count}", "multi {_count}", 0), 'multi 0');
78 is(__nx("single {_count}", "multi {_count}", 1), 'single 1');
79 is(__nx("single {_count}", "multi {_count}", 2), 'multi 2');
88 ol_is(__nx("single {_count}", "multi {_count}", 0), 'multi 0');
89 ol_is(__nx("single {_count}", "multi {_count}", 1), 'single 1');
90 ol_is(__nx("single {_count}", "multi {_count}", 2), 'multi 2');
8091
8192 #
8293 # Expand arrays
8495 {
8596 local $" = ', ';
8697 my @one = 'rabbit';
87 is((__x "files: {f}", f => \@files), "files: monkey, donkey");
88 is((__xn "one file: {f}", "{_count} files: {f}", @files, f => \@files),
98 ol_is((__x "files: {f}", f => \@files), "files: monkey, donkey");
99 ol_is((__xn "one file: {f}", "{_count} files: {f}", @files, f => \@files),
89100 "2 files: monkey, donkey");
90 is((__x "files: {f}", f => \@one), "files: rabbit");
91 is((__xn "one file: {f}", "{_count} files: {f}", @one, f => \@one),
101 ol_is((__x "files: {f}", f => \@one), "files: rabbit");
102 ol_is((__xn "one file: {f}", "{_count} files: {f}", @one, f => \@one),
92103 "one file: rabbit");
93104 }
94105
99110 my $s2 = __x "found {nr} files", nr => 5;
100111 my $t2 = $s2->(nr => 3);
101112 isa_ok($t2, 'Log::Report::Message');
102 is($s2, 'found 5 files');
103 is($t2, 'found 3 files');
113 ol_is($s2, 'found 5 files');
114 ol_is($t2, 'found 3 files');
104115
105116 # clone by overload
106117 my $s = __x "A={a};B={b}", a=>11, b=>12;
107118 isa_ok($s, 'Log::Report::Message');
108 ok(reftype $s, 'HASH');
119 is(reftype $s, 'HASH');
109120 is($s->toString, "A=11;B=12");
110121
111122 my $t = $s->(b=>13);
112123 isa_ok($t, 'Log::Report::Message');
113 ok(reftype $t, 'HASH');
124 is(reftype $t, 'HASH');
114125 isnt("$s", "$t");
115126 is($t->toString, "A=11;B=13");
116127 is($s->toString, "A=11;B=12"); # unchanged
122133 use constant PI => 4 * atan2(1, 1);
123134 my $approx = 'approx pi: 3.141593';
124135 is((sprintf "approx pi: %.6f", PI), $approx);
125 is((__x "approx pi: {approx}", approx => sprintf("%.6f", PI)), $approx);
126 is((__x "approx pi: {pi%.6f}", pi => PI), $approx);
136 ol_is((__x "approx pi: {approx}", approx => sprintf("%.6f", PI)), $approx);
137 ol_is((__x "approx pi: {pi%.6f}", pi => PI), $approx);
127138
128 is((__x "{perms} {links%2d} {user%-8s} {size%8d} {fn}"
139 ol_is((__x "{perms} {links%2d} {user%-8s} {size%8d} {fn}"
129140 , perms => '-rw-r--r--', links => 1, user => 'superman'
130141 , size => '1234567', fn => '/etc/profile')
131142 , '-rw-r--r-- 1 superman 1234567 /etc/profile');