[31641] in Perl-Users-Digest
Perl-Users Digest, Issue: 2904 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 7 09:09:35 2010
Date: Wed, 7 Apr 2010 06:09:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 7 Apr 2010 Volume: 11 Number: 2904
Today's topics:
Re: FAQ 1.2 Who supports Perl? Who develops it? Why i <brian.d.foy@gmail.com>
mock a method on a single object <beluchin@gmail.com>
Re: mock a method on a single object <willem@turtle.stack.nl>
Re: mock a method on a single object <naveedm9@gmail.com>
Re: mock a method on a single object <Peter@PSDT.com>
Re: software requirements again, take 483 <rvtol+usenet@xs4all.nl>
Re: software requirements again, take 483 <cwilbur@chromatico.net>
Re: software requirements again, take 483 <cwilbur@chromatico.net>
Re: software requirements again, take 483 <cartercc@gmail.com>
Re: software requirements again, take 483 <cwilbur@chromatico.net>
Re: software requirements again, take 483 <cartercc@gmail.com>
Re: software requirements again, take 483 <cwilbur@chromatico.net>
Re: software requirements again, take 483 <cartercc@gmail.com>
Re: STDIN number only <tadmc@seesig.invalid>
Re: STDIN number only sln@netherlands.com
VERSION in UNIVERSAL alternative? <john@castleamber.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 Apr 2010 02:38:55 -0600
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 1.2 Who supports Perl? Who develops it? Why is it free?
Message-Id: <070420100238553180%brian.d.foy@gmail.com>
In article <hpf1hp$gkq$1@speranza.aioe.org>, Philip Potter
<pgp@doc.ic.ac.uk> wrote:
> > 1.2: Who supports Perl? Who develops it? Why is it free?
> >
> [snip]
> > http://dev.perl.org/perl5/docs/p5p-faq.html , or you can subscribe to
> > the mailing list by sending perl5-porters-request@perl.org a
> > subscription request (an empty message with no subject is fine).
>
> That should be perl5-porters-subscribe@perl.org. I just send a test
> email from a nonsubscribed account to perl5-porters-request@ and got:
Thanks. I'll update the answer
------------------------------
Date: Tue, 6 Apr 2010 19:46:35 -0700 (PDT)
From: Belebele <beluchin@gmail.com>
Subject: mock a method on a single object
Message-Id: <11578cb9-d87e-4b64-8a49-d05ad1b6a2ce@r1g2000yqb.googlegroups.com>
How can I mock a method on a _single_ object (as opposed to mocking
the method on all the objects of a class)? Consider:
package Foo;
{
sub new {
my $class = shift;
return bless {}, $class;
}
sub bar { print "bar\n" }
}
my ($a_foo, $another_foo) = (new Foo(), new Foo());
sub print_something { print "something\n" }
*Foo::bar = *print_something; # I would like to change the behavior
for only $a_foo, but not for $another_foo
$a_foo->bar(); # print_something
$another_foo->bar(); # print_something
Thanks
------------------------------
Date: Wed, 7 Apr 2010 05:54:26 +0000 (UTC)
From: Willem <willem@turtle.stack.nl>
Subject: Re: mock a method on a single object
Message-Id: <slrnhro7gi.2m4p.willem@turtle.stack.nl>
Belebele wrote:
) How can I mock a method on a _single_ object (as opposed to mocking
) the method on all the objects of a class)? Consider:
I'm not sure what you mean by 'mocking', but if it means what I think it
means, I would think that Perl calls that 'blessing' ?
) my ($a_foo, $another_foo) = (new Foo(), new Foo());
) sub print_something { print "something\n" }
) *Foo::bar = *print_something; # I would like to change the behavior
) for only $a_foo, but not for $another_foo
) $a_foo->bar(); # print_something
) $another_foo->bar(); # print_something
Perhaps something like:
bless $a_foo, 'Foo::barbaz';
package Foo::barbaz
our @ISA = 'Foo::bar';
sub print_something { print "something\n" }
would do the trick ?
Although I'm still not entirely sure what you intend to do.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Wed, 7 Apr 2010 00:47:30 -0700 (PDT)
From: Naveed <naveedm9@gmail.com>
Subject: Re: mock a method on a single object
Message-Id: <d89b27fe-005e-42a1-8fc2-f39d74a82847@j21g2000yqh.googlegroups.com>
On Apr 7, 3:46=A0am, Belebele <beluc...@gmail.com> wrote:
> How can I mock a method on a _single_ object (as opposed to mocking
> the method on all the objects of a class)? Consider:
>
> package Foo;
> {
> =A0 =A0 =A0 =A0 sub new {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 my $class =3D shift;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return bless {}, $class;
> =A0 =A0 =A0 =A0 }
>
> =A0 =A0 =A0 =A0 sub bar { print "bar\n" }
>
> }
>
> my ($a_foo, $another_foo) =3D (new Foo(), new Foo());
> sub print_something { print "something\n" }
> *Foo::bar =3D *print_something; =A0# I would like to change the behavior
> for only $a_foo, but not for $another_foo
> $a_foo->bar(); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# print_som=
ething
> $another_foo->bar(); =A0 =A0 =A0 =A0 =A0 =A0 =A0 # print_something
>
> Thanks
Look at http://p3rl.org/Test::MockObject::Extends
------------------------------
Date: Wed, 07 Apr 2010 11:28:03 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: mock a method on a single object
Message-Id: <7%Zun.7858$kj3.6403@newsfe08.iad>
On Tue, 06 Apr 2010 19:46:35 -0700, Belebele wrote:
> How can I mock a method on a _single_ object (as opposed to mocking the
> method on all the objects of a class)? Consider:
>
> package Foo;
> {
> sub new {
> my $class = shift;
> return bless {}, $class;
> }
>
> sub bar { print "bar\n" }
> }
>
>
> my ($a_foo, $another_foo) = (new Foo(), new Foo()); sub print_something
> { print "something\n" } *Foo::bar = *print_something; # I would like to
> change the behavior for only $a_foo, but not for $another_foo
> $a_foo->bar(); # print_something
> $another_foo->bar(); # print_something
$ cat foo
#!/usr/local/bin/perl
use strict;
use warnings;
use 5.10.0;
package Foo;
sub bar { say "bar" }
sub new { bless {}, shift }
package main;
use Test::MockObject::Extends;
my $x = Foo->new;
$x = Test::MockObject::Extends->new( $x );
$x->mock( bar => sub { say "mocked" } );
my $y = Foo->new;
$x->bar;
$y->bar;
$ ./foo
mocked
bar
--
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/
------------------------------
Date: Tue, 06 Apr 2010 21:09:24 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: software requirements again, take 483
Message-Id: <4bbb86e4$0$22938$e4fe514c@news.xs4all.nl>
Jürgen Exner wrote:
> And I cannot imagine how email or the Internet or Usenet would work
> without any written specs and protocols.
Most of them document long standing practice.
--
Ruud
------------------------------
Date: Sun, 04 Apr 2010 17:11:58 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: software requirements again, take 483
Message-Id: <867hom3otd.fsf@mithril.chromatico.net>
>>>>> "cc" == ccc31807 <cartercc@gmail.com> writes:
cc> The business guy was out of the office at a conference. All I
cc> had was the log file and that he wanted it by Monday. Initially,
cc> I didn't even know what it was that he wanted, but it wasn't
cc> difficult to guess. I didn't want to wait until I knew the
cc> requirements in toto when I knew I could do 90% with the
cc> information I had.
You *guessed* the requirements? You dove in without being sure that is
what he wanted?
This is the core of your problem. Not only is the development process
at your workplace completely ass-backwards, you are *participating in*
and *reinforcing* its ass-backwardsness.
Until that changes, the only reasonable response to your complaints
about your workplace is really, "stfu, it's your own damn fault."
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Sun, 04 Apr 2010 17:07:59 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: software requirements again, take 483
Message-Id: <86eiiv2afk.fsf@mithril.chromatico.net>
>>>>> "cc" == ccc31807 <cartercc@gmail.com> writes:
cc> We'll get this sorted out on Monday so I'm not worried about
cc> it. The point is that the technical person can't work without
cc> knowing what the requirements are, and at least in my situation,
cc> I am often assigned work with unclear, ambiguous, or absent
cc> requirements.
Yes, and when a professional software engineer is handed unclear,
ambiguous, or absent requirements, it is one of his responsibilities to
see that they are clarified, disambiguated, or written at all.
That is the point that you do not seem to wish to understand.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Tue, 6 Apr 2010 13:53:01 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: software requirements again, take 483
Message-Id: <f903b4d0-90b7-41f8-a463-46f624fc085f@r1g2000yqb.googlegroups.com>
On Apr 4, 5:07=A0pm, Charlton Wilbur <cwil...@chromatico.net> wrote:
> Yes, and when a professional software engineer is handed unclear,
> ambiguous, or absent requirements, it is one of his responsibilities to
> see that they are clarified, disambiguated, or written at all.
>
> That is the point that you do not seem to wish to understand.
It's not that I don't wish to understand the point. In some cases, the
end user doesn't know the requirements until he has a handle on the
data. An end user that doesn't understand the problem can't specify
clear and precise requirements.
In order to follow your advice to clarify, disambiguate, or reduce to
writing the requirements, it's sometimes necessary to write code that
does something. We don't always have the luxury of having a complete
and precise specification before writing the first line of code. This
is one of the challenges that the spiral development cycle was
designed for.
CC.
------------------------------
Date: Tue, 06 Apr 2010 17:03:53 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: software requirements again, take 483
Message-Id: <8639z82szq.fsf@mithril.chromatico.net>
>>>>> "R" == Ruud <rvtol+usenet@xs4all.nl> writes:
R> Do they really still exist, these environments where they write
R> up specifications and sign them off and such? What a waste!
R> Go and work in a communicative environment, where the "business"
R> and the "developers" continuously share and improve the business
R> knowledge, and help each other to get results, with noticeable
R> improvements every day.
...and what you're doing is just writing the specifications iteratively
and interactively. If you don't know what your goals are, you have no
idea if you're making any progress towards them.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Wed, 7 Apr 2010 04:57:07 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: software requirements again, take 483
Message-Id: <67f8266e-7844-44c3-97f4-3f07c370c658@b33g2000yqc.googlegroups.com>
On Apr 6, 5:03=A0pm, Charlton Wilbur <cwil...@chromatico.net> wrote:
> ...and what you're doing is just writing the specifications iteratively
> and interactively. =A0
What's wrong with that? Seems to be that the basis of 'requirements
engineering' is that requirements are developed in an empirical,
deductive manner, rather than a top down all-or-nothing manner.
> If you don't know what your goals are, you have no
> idea if you're making any progress towards them.
This is a truism, and like all other truisms has limited application.
The 'goal' might be to grow the business, but the devil is in the
details. I did a project recently analyzing call center data,
developing scripts showing when, where, and why the users called. Some
areas had a lot more calls than others, and I recall a heated
discussion as to whether it was because these units were doing a
better job than the others, or a worse job than the others.
The 'goal' was to service the users. Does a high call volume mean that
you are doing a better job? or a worse job? Do you want to increase
the help calls, which might indicate that people were using the
product? Or do you want to decrease the help calls, which might
indicate that people were actually using the product rather than
having problems with it?
CC.
------------------------------
Date: Wed, 07 Apr 2010 08:33:09 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: software requirements again, take 483
Message-Id: <86vdc31lyy.fsf@mithril.chromatico.net>
>>>>> "cc" == ccc31807 <cartercc@gmail.com> writes:
>> If you don't know what your goals are, you have no idea if you're
>> making any progress towards them.
cc> This is a truism, and like all other truisms has limited
cc> application. The 'goal' might be to grow the business, but the
cc> devil is in the details.
"Make the business grow" is a strategic goal. Someone who knows the
business needs to derive some tactical goals from that -- things that,
if the workers should accomplish them, should result in the business
growing. But "make the business grow" is a completely useless goal to
give to a programmer.
More to the point, you cannot invalidate the usefulness of goals in
software development by pointing out the difficulty of working towards a
vague strategic goal. Yes, that's a goal. No, it's not a useful goal
for a programmer to work towards without an intermediate goal.
Time and time again you're given a vague specification or no
specification at all, you dive in headfirst, it turns out to be not what
the person actually wanted, you take all the blame, and then you vent
here. You are contributing to and enhancing the problem that you're
complaining about, and you're too stubborn or stupid to see it. You are
building the hell you're in, and when other people point out that you
are doing so, you come up with a paragraph of quasi-management speak to
justify why you should keep on building your own hell.
If you want help, you've come to the right place. If you want to vent
about how miserable your life is and how nobody understands you,
livejournal is that way.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Wed, 7 Apr 2010 06:08:56 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: software requirements again, take 483
Message-Id: <e8fdf9b4-37dd-4594-9663-522f88709f8a@g11g2000yqe.googlegroups.com>
On Apr 7, 8:33=A0am, Charlton Wilbur <cwil...@chromatico.net> wrote:
> If you want help, you've come to the right place. =A0If you want to vent
> about how miserable your life is and how nobody understands you,
> livejournal is that way.
I think you might have misinterpreted the thrust of the conversation.
My intention was to provoke a discussion about the process of
developing applications, which in mu case means little scripts that
import data and export information.
I don't want or need 'help' in dealing with my personal employment
situation. I don't want or need to 'vent' in the sense garnering
sympathy. I certainly don't want to give the impression that my life
is miserable, because it's not.
These kinds of discussions have value (IMO) because they allow us to
share experiences and ideas, which help in the day to day practice of
our profession. My clients aren't stupid, ignorant fools who exist
merely to make my life hell, but smart, knowledgeable professionals
who want to grow the enterprise. It's my job to help them by giving
them the information they need.
The fact that they might lack the skills to do this, and the
vocabulary to talk about the process, just makes the job more
challenging, and my own role more important.
CC.
>
> Charlton
>
> --
> Charlton Wilbur
> cwil...@chromatico.net
------------------------------
Date: Tue, 06 Apr 2010 14:45:08 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: STDIN number only
Message-Id: <slrnhrn3ia.i4b.tadmc@tadbox.sbcglobal.net>
Steve M <stevem_clipthis_@clubtrout.com> wrote:
> On 4/5/2010 5:41 PM, Tad McClellan wrote:
>> Jürgen Exner<jurgenex@hotmail.com> wrote:
>>> Don Pich<dpich@polartel.com> wrote:
>>
>>
>>>> What I want to do is that if a user enters anything but a number from 0
>>>> to 254, they will get the print statement above.
>>
>>> I would solve this in two steps:
>>
>>
>> I'd do it in two (different) steps:
>>
>> chomp $num;
>> if ( $num =~ /\D/ or $num> 255 ) {
>> print "'$num' is not between 0 and 254\n";
>> }
>>
>> :-)
>>
>>
>
> Certainly cleaner than the verbose thought I'd posted, and it works well
> except for the situation where the user just hits the enter key without
> entering a value... perhaps:
>
> chomp $num;
> if ( !$num or $num =~ /\D/ or $num > 255 ) {
if ( $num =~ /^$/ or $num =~ /\D/ or $num > 255 ) {
or
if ( !length $num or $num =~ /\D/ or $num > 255 ) {
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Tue, 06 Apr 2010 14:09:07 -0700
From: sln@netherlands.com
Subject: Re: STDIN number only
Message-Id: <st7nr5lredqh64ihgaf05el8pabu7v9i6d@4ax.com>
On Mon, 05 Apr 2010 20:44:59 -0700, sln@netherlands.com wrote:
>On Mon, 05 Apr 2010 12:54:17 -0500, Don Pich <dpich@polartel.com> wrote:
>
>>What I want to do is that if a user enters anything but a number from 0
>>to 254, they will get the print statement above. If it is a number, then
>>flow it through. I am having a very tough time trying to have this just
>>entered as a number. I have tried various regex examples to fix this.
>>But none will kick out an error if I enter a string of text.
>>
>>different regex strings I've tried:
>>
>>$OCT1 =~ s/.*?(\d+).*/$1/;
>>m/^-?\d+$/
>>m/^-?\d+[\/|\.]\d+$/
>>
>
>You could always do it all at once instead of single quad parts.
>
This version is a little more forgiving when enterring the ip.
It mainly gets the dotted quad part, and optional bits in
CIDR notation.
I was going to do this anyway, if you need it take it.
The network stuff at the bottom was gleaned from Wikipedia:
http://en.wikipedia.org/wiki/Subnetwork
I'm not a network expert, so its roll your own or whatever.
Without the CIDR notation, it just spits out the input IP.
-sln
----------------------------------
Some input/output:
c:\temp>perl ip_quad_enter.pl
> enter IP ('q' quits): 192 . 168. 5. 130 / 24
Ip address: 192.168.5.130 (/24)
Network address: 192.168.5.0
Host identifier: 0.0.0.130
Available sub-networks: 1
Available Hosts per network: 256
Total usable hosts: 254
c:\temp>perl ip_quad_enter.pl
> enter IP ('q' quits): 2. 1. 44. 127 / 29
Ip address: 2.1.44.127 (/29)
Network address: 2.1.44.120
Host identifier: 0.0.0.7
Available sub-networks: 32
Available Hosts per network: 8
Total usable hosts: 6
c:\temp>perl ip_quad_enter.pl
> enter IP ('q' quits): 66. 7. 100. 22
Ip address: 66.7.100.22
----------------------------------
## --------------------
## ip_quad_enter.pl
## keyboard entry
## : misc ip stuff
## -sln
## --------------------
use strict;
use warnings;
my (@quad, $ip, $bits);
EnterIP:
while (1)
{
@quad = ();
print "\n > enter IP ('q' quits): ";
$ip = <STDIN>;
chomp $ip;
last EnterIP if (lc($ip) eq 'q');
while ( $ip =~ /
(?: ## Quad Part
\s* # optional whitespaces
\.?(?<!^\.) # '.' begin quad part not at beginning of line
\s* # optional whitespaces
(\d+) # quad part digits
\s* # optional whitespaces
(?=\.|$|\/) # end quad part (not consumed)
)
| ## OR
(?=.) # any invalid character (not consumed)
/xg)
{
if ( !defined $1) {
print " _ '", substr($ip, pos($ip)), "' is invalid\n";
redo EnterIP;
}
if ( $1 > 255) {
print " _ ", int($1), " is out of range (0-255)\n";
redo EnterIP;
}
push @quad, int($1);
if ( @quad == 4)
{
if ( length($ip) != pos($ip))
{
my $mask = substr($ip, pos($ip));
if ( $mask =~ /^\s* \/ \s* (\d+) \s*/xg)
{
if ( length($mask) != pos($mask)) {
print " _ extra text in cidr notation: '",
substr($ip, pos($ip)), "'\n";
redo EnterIP;
}
elsif ( $1 < 24 || $1 > 31) { # Class C
print " _ \/ ", int($1), " is out of range (24-31)\n";
redo EnterIP;
}
else {
$bits = int($1);
}
}
else {
print " _ extra text in ip address: '",
substr($ip, pos($ip)), "'\n";
redo EnterIP;
}
}
last EnterIP;
}
}
print " _ not enough quad parts\n";
}
if (@quad != 4) {
print "user exit ..\n";
exit 1 ;
}
print "\n";
if (defined $bits) {
my $borrowed = 256 - (2**(32 - $bits));
print "Ip address: $quad[0].$quad[1].$quad[2].$quad[3] (/$bits)\n";
print "Network address: $quad[0].$quad[1].$quad[2].", ($quad[3] & $borrowed), "\n";
print "Host identifier: 0.0.0.", ($quad[3] & ~$borrowed), "\n";
print "Available sub-networks: ", (2**(8 - (32-$bits))), "\n";
print "Available Hosts per network: ", (2**(32-$bits)), "\n";
my $usablehosts = (2**(32-$bits))-2;
print "Total usable hosts: ", ($usablehosts > 1 ? $usablehosts : "2 (point-to-point links only)"), "\n";
}
else {
print "Ip address: $quad[0].$quad[1].$quad[2].$quad[3]\n";
}
exit 0;
__END__
------------------------------
Date: Tue, 06 Apr 2010 18:43:23 -0500
From: John Bokma <john@castleamber.com>
Subject: VERSION in UNIVERSAL alternative?
Message-Id: <876344m9k4.fsf@castleamber.com>
Hi,
I currently use an eval to obtain VERSION of the parent class [1]. I noted
that UNIVERSAL has VERSION, however,
http://perldoc.perl.org/UNIVERSAL.html
states that " import ... and VERSION ), however it is usually harmful to
do so. Please don't do this in new code.
So, what's the alternative / better solution (and why isn't this in the
documentation ;-) ).
[1] my $package = ref $self;
my $version = eval "\$${package}::VERSION";
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2904
***************************************