/usr/share/perl5/Lire/Param.pm is in lire 2:2.1.1-2.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | package Lire::Param;
use strict;
use Lire::Config::TypeSpec;
use Lire::DataTypes qw/ check_xml_name check_type /;
use Lire::Utils qw/ check_param /;
use Lire::I18N qw/ dgettext_para /;
=pod
=head1 NAME
Lire::Param - Object which represents a parameter in a XML specification.
=head1 DESCRIPTION
Lire::Param are objects which represent parameters in an XML
specification. The object is used to represent the parameter's
specification as well as its current value.
=head2 new( 'name' => $name, 'type' => $type, [ 'default' => $default ] )
Creates a new Lire::Param object.
=cut
sub new {
my ( $class, %params ) = @_;
check_param( $params{'name'}, 'name', \&check_xml_name );
check_param( $params{'type'}, 'type', \&check_type );
my $self = bless { 'name' => $params{'name'},
'type' => $params{'type'},
'i18n_domain' => $params{'i18n_domain'} || 'lire',
'description' => $params{'description'},
}, $class;
$self->default( $params{'default'} )
if defined $params{'default'};
$self->value( $params{'value'} )
if defined $params{'value'};
return $self;
}
=pod
=head2 name()
Returns the name of this parameter.
=cut
sub name {
return $_[0]->{'name'};
}
=pod
=head2 type()
Returns this parameter's type.
=cut
sub type {
return $_[0]->{'type'};
}
=pod
=head2 value( [ $new_value ] )
Returns (and optionnally modifies) the current value for this
parameter. If no value was set, but a default is available, the
default value will be returned.
=cut
sub value {
my ($self, $value ) = @_;
if ( @_ == 2 ) {
if ( defined $value ) {
check_param( $value, 'value',
$Lire::DataTypes::VALIDATORS{$self->{'type'}} );
$self->{'value'} = $value;
} else {
$self->{'value'} = undef;
}
}
# Check for default
if ( defined $self->{'value'}) {
return $self->{'value'};
} else {
return $self->default();
}
}
=pod
=head2 default( [ $new_default ] )
Returns (and optionnally changes) the parameter's default value.
=cut
sub default {
my ( $self, $default ) = @_;
if ( defined $default ) {
check_param( $default, 'default',
$Lire::DataTypes::VALIDATORS{$self->{'type'}} );
$self->{'default'} = $default;
}
return $self->{'default'};
}
=pod
=head2 description( [ $new_description ] )
Returns (and optionnally changes) the current parameter's description.
=cut
sub description {
my ( $self, $desc ) = @_;
if ( @_ == 2 ) {
$self->{'description'} = $desc;
}
return dgettext_para( $self->{'i18n_domain'},
$self->{'description'} );
}
=pod
=head2 as_type_spec()
Returns a Lire::Config::TypeSpec object which adequately represents the
current parameter.
=cut
my %types2spec = ( 'int' => 'Lire::Config::IntegerSpec',
'bool' => 'Lire::Config::BooleanSpec',
'filename', => 'Lire::Config::FileSpec' );
sub as_type_spec {
my $self = $_[0];
my $type = $types2spec{$self->{'type'}} || 'Lire::Config::StringSpec';
my $spec = $type->new( 'name' => $self->{'name'},
'i18n_domain' => $self->{'i18n_domain'},
'description' => $self->{'description'} );
$spec->default( $spec->instance( 'value' => $self->{'default'} ) )
if defined $self->{'default'};
return $spec;
}
# keep perl happy
1;
__END__
=pod
=head1 SEE ALSO
Lire::Config::TypeSpec(3pm), Lire::XMLSpecContainer(3pm)
=head1 AUTHOR
Francis J. Lacoste <flacoste@logreport.org>
=head1 VERSION
$Id: Param.pm,v 1.13 2006/07/23 13:16:29 vanbaal Exp $
=head1 COPYRIGHT
Copyright (C) 2001,2004 Stichting LogReport Foundation LogReport@LogReport.org
This file is part of Lire.
Lire is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html.
=cut
|