Met_v04.pm

filter: Statementstmt 85.7% 12 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 89.4% 17 / 19 CC 1 SCAR 0.6
CC
1
Cov
86%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Util.pm ↑ Summary Met.pm »
1 # P2P::pDonkey::Met_v04.pm
2 #
3 # Copyright (c) 2003-2004 Alexey klimkin <klimkin at cpan.org>.
4 # All rights reserved.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the same terms as Perl itself.
7 #
8 package P2P::pDonkey::Met_v04;
9  
10 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 require Exporter;
15  
16 our $VERSION = '0.05';
17  
18 our @ISA = qw(Exporter);
19  
20 # Items to export into callers namespace by default. Note: do not export
21 # names by default without a very good reason. Use EXPORT_OK instead.
22 # Do not simply export all your public functions/methods/constants.
23  
24 # This allows declaration use P2P::pDonkey ':all';
25 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
26 # will save memory.
27 our %EXPORT_TAGS = ( 'all' => [ qw(
28 MT_PARTMET_v04
29  
30 unpackPartMet_v04 packPartMet_v04
31 readPartMet_v04 writePartMet_v04
32  
33 unpackKnownMet_v04 packKnownMet_v04
34 readKnownMet_v04 writeKnownMet_v04
35 ) ] );
36  
37 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
38  
39 our @EXPORT = qw(
40
41 );
42  
43 1 ▶use Data::Hexdumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 0 ▶use P2P::pDonkey::Meta ':all';
Subroutine BEGIN: called CC=1 SCAR=2.6
45 use P2P::pDonkey::Meta_v04 ':all';
46 use P2P::pDonkey::Met qw( readFile writeFile MT_KNOWNMET );
47  
48 my $debug = 0;
49  
50 use constant MT_PARTMET_v04 => 0xe0;
51  
52 sub unpackPartMet_v04 {
53 my $v = &unpackB;
54 $v == MT_PARTMET_v04 or return;
55 return &unpackFileInfo_v04;
56 }
57 sub packPartMet_v04 {
58 return packB(MT_PARTMET_v04) . &packFileInfo_v04;
59 }
60  
61 sub readPartMet_v04 {
62 my ($fname) = @_;
63 my ($off, $buf, $res);
64 $buf = readFile($fname, MT_PARTMET_v04) or return;
65 $off = 0;
66 $res = unpackPartMet_v04($$buf, $off);
67 $res->{Path} = $fname;
68 print "$off ", length $$buf, "\n";
69 if ($res && $off != length $$buf) {
70 warn "Unhandled bytes at the end:\n", hexdump(data=>$$buf, start_position=>$off);
71 }
72 return $res;
73 }
74 sub writePartMet_v04 {
75 my ($fname, $p) = @_;
76 my $buf = packPartMet_v04($p);
77 return writeFile($fname, \$buf);
78 }
79  
80 sub unpackKnownMet_v04 {
81 &unpackB == MT_KNOWNMET or return;
82 return &unpackFileInfoList_v04;
83 }
84 sub packKnownMet_v04 {
85 return packB(MT_KNOWNMET) . &packFileInfoList_v04;
86 }
87 sub readKnownMet_v04 {
88 my ($fname) = @_;
89 my ($off, $buf, $res);
90 $buf = readFile($fname, MT_KNOWNMET) or return;
91 $off = 0;
92 $res = unpackKnownMet_v04($$buf, $off);
93 if ($res && $off != length $$buf) {
94 warn "Unhandled bytes at the end:\n", hexdump(data=>$$buf, start_position=>$off);
95 }
96 return $res;
97 }
98 sub writeKnownMet_v04 {
99 my ($fname, $p) = @_;
100 my $buf = packKnownMet_v04($p);
101 return writeFile($fname, \$buf);
102 }
103  
104 1;
« Util.pm ↑ Summary Met.pm »