App-Context
view release on metacpan or search on metacpan
lib/App/Reference.pm view on Meta::CPAN
* Signature: $ref->print();
* Param: void
* Return: void
* Throws: App::Exception
* Since: 0.01
Sample Usage:
$context->print();
=cut
sub print {
my ($self, $ref) = @_;
$ref = $self if (!$ref);
print $self->dump($ref);
}
#############################################################################
# PROTECTED METHODS
#############################################################################
=head1 Protected Methods:
The following methods are intended to be called by subclasses of the
current class.
=cut
#############################################################################
# create()
#############################################################################
=head2 create()
The create() method is used to create the Perl structure that will
be blessed into the class and returned by the constructor.
It may be overridden by a subclass to provide customized behavior.
* Signature: $ref = App::Reference->create("array", @args)
* Signature: $ref = App::Reference->create($arrayref)
* Signature: $ref = App::Reference->create($hashref)
* Signature: $ref = App::Reference->create($hashref, %named)
* Signature: $ref = App::Reference->create(%named)
* Param: $hashref {}
* Param: $arrayref []
* Return: $ref ref
* Throws: App::Exception
* Since: 0.01
Sample Usage:
=cut
sub create {
my $self = shift;
print "create(@_)\n" if ($App::DEBUG);
return {} if ($#_ == -1);
if (ref($_[0]) ne "") {
return $_[0] if ($#_ == 0);
App::Exception->throw(error => "Reference->create(): args supplied with an ARRAY ref\n")
if (ref($_[0]) eq "ARRAY");
my ($ref, $i);
$ref = shift;
for ($i = 0; $i < $#_; $i += 2) {
#print "arg: $_[$i] => $_[$i+1]\n";
$ref->{$_[$i]} = $_[$i+1];
}
return $ref;
}
if ($_[0] eq "array") {
shift;
return [ @_ ];
}
elsif ($#_ % 2 == 0) {
App::Exception->throw(error => "Reference->create(): Odd number of named parameters\n");
}
return { @_ };
}
#############################################################################
# _init()
#############################################################################
=head2 _init()
The _init() method is called from within the standard Reference constructor.
The _init() method in this class does nothing.
It allows subclasses of the Reference to customize the behavior of the
constructor by overriding the _init() method.
* Signature: _init($named)
* Param: $named {} [in]
* Return: void
* Throws: App::Exception
* Since: 0.01
Sample Usage:
$ref->_init($args);
=cut
sub _init {
my $self = shift;
}
#############################################################################
# PRIVATE METHODS
#############################################################################
=head1 Private Methods:
The following methods are intended to be called only within this class.
=cut
=head1 ACKNOWLEDGEMENTS
* Author: Stephen Adkins <spadkins@gmail.com>
* License: This is free software. It is licensed under the same terms as Perl itself.
=head1 SEE ALSO
none
=cut
1;
( run in 0.891 second using v1.01-cache-2.11-cpan-39bf76dae61 )