Hello, once more, to all you most esteemed residents of this most wonderful inter-web resource,

Once more I prostrate myself before you in seeking the answer to a problem that's had me tearing my hair out - I had little enough to start with;-)

The following is, I believe, valid code - but when compiled, generates warnings (c/w a not entirely unexpected error - that I can explain) and for the life of me, I can't see the problem.

The code (from file SVC/DnsEntity.pm):

package SVC::DnsEntity::IPv6; use strict; use warnings; use Carp; my $value; sub new { my $self = shift; bless \( my $scalar ), ref $self || $self; } sub value { $value } package SVC::DnsEntity::IPv4; use strict; use warnings; use Carp; my $value; sub new { my $self = shift; my $_value = shift || croak "No IP address?!"; croak "Invalid IP address" unless $_value =~ /(:?\d{}1,3){4}/; map { croak "Octet out of bounds" unless $_ >= 0 && $_ <= 255 } split /\./, $_value; bless \$_value, ref $self || $self; } sub value { my $self = shift; $$self; } package SVC::DnsEntity; use strict; use warnings; use Carp; use Net::Ping; use Fatal qw/Net::Ping::new Net::Ping::ping/; use SVC::CmdSession; use vars q/%attribs/; BEGIN { no strict q/refs/; map { my $_sub = $_; eval { *$_sub = sub { $attribs{$_sub} } }; croak "Failed to create $_sub - $@" if $@; } qw/hostname ip_address/; } %attribs = ( hostname => undef, type => q/IPv4/, ip_address => undef, pinger => undef, ); my $DEFAULT_TIMEOUT = 1; sub new { my $self = shift; my $args = { ( %attribs ), @_ }; croak "No IP version type - expected IPv[46]" unless $args->{type}->can(qw/new/); my $ver_class = __PACKAGE__ . "\:\:$args->{type}"; warn "ver_class: $ver_class"; $args->{ip_address} = $ver_class->new($args->{ip_address}) if $args->{ip_address}; $attribs{pinger} = Net::Ping->new(); bless \( my %data = %attribs ), ref $self || $self; }
The warnings & errors:
"my" variable $value masks earlier declaration in same scope at SVC/Dn +sEntity.pm line 28. Subroutine new redefined at SVC/DnsEntity.pm line 76. Can't bless non-reference value at SVC/CmdSession.pm line 17.
It's almost like the compiler doesn't see &/or recognise the package statements ...

I would be obliged if someone could point out what I am patently too close to see.

TIA & Rgds,

Update

Many thanx to zentara and Fletch who, between them pointed out just how much I couldn't see the wood for the trees.

A user level that continues to overstate my experience :-))

In reply to To be, or not to be, a package? That is the question by Bloodnok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.