File: File.pm

package info (click to toggle)
libtransmission-client-perl 0.0806-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 304 kB
  • sloc: perl: 3,004; makefile: 2
file content (127 lines) | stat: -rw-r--r-- 1,888 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# ex:ts=4:sw=4:sts=4:et
package Transmission::Torrent::File;
# See Transmission::Client for copyright statement.

=head1 NAME

Transmission::Torrent::File - file within a Transmission torrent

=cut

use Moose;
use Transmission::Types ':all';

with 'Transmission::AttributeRole';

=head1 ATTRIBUTES

=head2 id

 $int = $self->id;

This file index in the files list.

=cut

has id => (
    is => 'ro',
    isa => 'Int',
    default => -1,
);

=head2 length

 $num = $self->length;

File size in bytes.

=head2 name

 $str = $self->name;

=head2 bytes_completed

 $num = $self->bytes_completed;

Bytes downloaded.

=head2 wanted

 $bool = $self->wanted;

Flag which decides if this file will be downloaded or not.

=cut

has wanted => (
    is => 'rw',
    isa => boolean,
    coerce => 1,
    default => 1,
);

=head2 priority

 $int = $self->priority;

Low, Normal or High, with the respectable values: -1, 0 and 1.

=cut

has priority => (
    is => 'rw',
    isa => number,
    coerce => 1,
    default => 0,
);

{
    my %read = (
        key             => string,
        length          => number,
        name            => string,
        bytesCompleted  => number,
    );

    for my $camel (keys %read) {
        my $name = __PACKAGE__->_camel2Normal($camel);
        has $name => (
            is => 'ro',
            isa => $read{$camel},
            coerce => 1,
            writer => "_set_$name",
        );
    }
}

=head1 METHODS

=head2 BUILDARGS

 $hash_ref = $class->BUILDARGS(\%args);

Convert keys in C<%args> from "CamelCase" to "camel_case".

=cut

sub BUILDARGS {
    my $self = shift;
    my $args = $self->SUPER::BUILDARGS(@_);

    for my $camel (keys %$args) {
        my $key = __PACKAGE__->_camel2Normal($camel);
        $args->{$key} = delete $args->{$camel};
    }

    return $args;
}

=head1 LICENSE

=head1 AUTHOR

See L<Transmission::Client>

=cut

1;