blib/lib/PL/sort.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 9 | 19 | 47.3 |
branch | 0 | 6 | 0.0 |
condition | 0 | 3 | 0.0 |
subroutine | 3 | 5 | 60.0 |
pod | 2 | 2 | 100.0 |
total | 14 | 35 | 40.0 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package PL::sort; | ||||||
2 | |||||||
3 | 1 | 1 | 712 | use warnings; | |||
1 | 2 | ||||||
1 | 37 | ||||||
4 | 1 | 1 | 6 | use strict; | |||
1 | 2 | ||||||
1 | 37 | ||||||
5 | 1 | 1 | 15 | use vars qw( $VERSION @ISA @EXPORT_OK ); | |||
1 | 6 | ||||||
1 | 889 | ||||||
6 | #---------------------------------------------------------------------- | ||||||
7 | require Exporter; | ||||||
8 | #====================================================================== | ||||||
9 | $VERSION = '0.2'; | ||||||
10 | @ISA = qw(Exporter); | ||||||
11 | @EXPORT_OK = qw( plsort plcmp ); | ||||||
12 | #====================================================================== | ||||||
13 | my $c = 0; | ||||||
14 | my %pos = map { $_ => $c++ } 'A', 'a', "\x{104}", , "\x{105}", 'B', 'b', 'C', 'c', "\x{106}", "\x{107}", 'D', 'd', 'E', 'e', "\x{118}", "\x{119}", 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', "\x{141}", "\x{142}", 'M', 'm', 'N', 'n', "\x{143}", "\x{144}", 'O', 'o', "\x{d3}", "\x{f3}", 'P', 'p', 'R', 'r', 'S', 's', "\x{15a}", "\x{15b}", 'T', 't', 'U', 'u', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z', "\x{17b}", "\x{17c}", "\x{179}", "\x{17a}"; | ||||||
15 | #====================================================================== | ||||||
16 | sub plcmp { | ||||||
17 | 0 | 0 | 1 | my ($sa, $sb) = @_; | |||
18 | |||||||
19 | 0 | my @a = split( //o, $sa ); | |||||
20 | 0 | my @b = split( //o, $sb ); | |||||
21 | |||||||
22 | |||||||
23 | 0 | 0 | my $l = @a > @b ? @b : @a; | ||||
24 | |||||||
25 | 0 | for my $i ( 0 .. $#a ){ | |||||
26 | 0 | 0 | 0 | my $r = exists $pos{ $a[ $i ] } && exists $pos{ $b[ $i ] } ? $pos{ $a[ $i ] } <=> $pos{ $b[ $i ] } : $a[ $i ] cmp $b[ $i ]; | |||
27 | 0 | 0 | return $r if $r; | ||||
28 | } | ||||||
29 | |||||||
30 | 0 | return $sa cmp $sb; | |||||
31 | } | ||||||
32 | #====================================================================== | ||||||
33 | sub plsort { | ||||||
34 | 0 | 0 | 1 | return sort { plcmp($a, $b) } @_; | |||
0 | |||||||
35 | } | ||||||
36 | #====================================================================== | ||||||
37 | 1; | ||||||
38 | |||||||
39 | =head1 NAME | ||||||
40 | |||||||
41 | PL::Sort | ||||||
42 | |||||||
43 | |||||||
44 | =head1 SYNOPSIS | ||||||
45 | |||||||
46 | use PL::Sort qw( plcmp plsort ); | ||||||
47 | |||||||
48 | my @sorted_1 = sort { plcmp( $a, $b ) } "N\x{f3}w", "Now", "N\x{f3}"; | ||||||
49 | my @sorted_2 = plsort( "N\x{f3}w", "Now", "N\x{f3}" ); | ||||||
50 | |||||||
51 | =head1 DESCRIPTION | ||||||
52 | |||||||
53 | Implements polish sorting conventions, indepentent on current locales in effect, which are often bad. | ||||||
54 | |||||||
55 | =head1 SUBROUTINES/METHODS | ||||||
56 | |||||||
57 | =over 4 | ||||||
58 | |||||||
59 | =item B |
||||||
60 | |||||||
61 | Subroutine, that makes comparison of two strings. | ||||||
62 | |||||||
63 | =item B |
||||||
64 | |||||||
65 | Subroutine, that sort a list of a strings. | ||||||
66 | |||||||
67 | =back | ||||||
68 | |||||||
69 | =head1 DEPENDENCIES | ||||||
70 | |||||||
71 | None. | ||||||
72 | |||||||
73 | =head1 INCOMPATIBILITIES | ||||||
74 | |||||||
75 | None known. | ||||||
76 | |||||||
77 | =head1 BUGS AND LIMITATIONS | ||||||
78 | |||||||
79 | None known. | ||||||
80 | |||||||
81 | =head1 AUTHOR | ||||||
82 | |||||||
83 | Strzelecki Ćukasz |
||||||
84 | |||||||
85 | =head1 LICENCE AND COPYRIGHT | ||||||
86 | |||||||
87 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||
88 | |||||||
89 | See http://www.perl.com/perl/misc/Artistic.html | ||||||
90 |