[Catalyst] assigning vars to $c-stash

2007-03-12 Thread Octavian Rasnita

Hi,

I have a $hash hash reference and I want to add all its elements to the 
stash. How can I do this? Do I need to use a loop and assign each element 
one by one?


I have seen that it is not possible to use $c-stash = $hash;

Can I use something else than

foreach(keys %$hash) {
$c-stash-{$_} = $hash-{$_};
}

Thank you.

Octavian


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] assigning vars to $c-stash

2007-03-12 Thread Carl Franks

On 12/03/07, Octavian Rasnita [EMAIL PROTECTED] wrote:

I have a $hash hash reference and I want to add all its elements to the
stash. How can I do this? Do I need to use a loop and assign each element
one by one?

I have seen that it is not possible to use $c-stash = $hash;


%{ $c-stash } = ( %{ $c-stash }, %$hash );
would also work, which combines both hashes.

This is very much a perl references problem - not something cat-specific.

See `perldoc perlref` for more info.

Cheers,
Carl

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] assigning vars to $c-stash

2007-03-12 Thread Matt Lawrence

Carl Franks wrote:

On 12/03/07, Octavian Rasnita [EMAIL PROTECTED] wrote:

I have a $hash hash reference and I want to add all its elements to the
stash. How can I do this? Do I need to use a loop and assign each 
element

one by one?

I have seen that it is not possible to use $c-stash = $hash;


%{ $c-stash } = ( %{ $c-stash }, %$hash );
would also work, which combines both hashes.

This is very much a perl references problem - not something cat-specific.

See `perldoc perlref` for more info.


I'm a fan of slicing, no need to construct a new hash:

@{$c-stash}{keys %$hash} = values %$hash;

Matt


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] assigning vars to $c-stash

2007-03-12 Thread Robert 'phaylon' Sedlacek

Octavian Rasnita wrote:

I have a $hash hash reference and I want to add all its elements to the 
stash. How can I do this? Do I need to use a loop and assign each 
element one by one?


I have seen that it is not possible to use $c-stash = $hash;

Can I use something else than

foreach(keys %$hash) {
$c-stash-{$_} = $hash-{$_};
}


Just

  $c-stash( %$hash );

should do it, iirc.

--
# Robert 'phaylon' Sedlacek
# Perl 5/Catalyst Developer in Hamburg, Germany
{ EMail = ' [EMAIL PROTECTED] ', Web = ' http://474.at ' }

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] assigning vars to $c-stash

2007-03-12 Thread Eden Cardim

On 3/12/07, Robert 'phaylon' Sedlacek [EMAIL PROTECTED] wrote:


   $c-stash( %$hash );


$c-stash( $hash );

is a little bit faster...

--
Eden Cardim
Instituto Baiano de Biotecnologia
Núcleo de Biologia Computacional e Gestão de Informações Biotecnológicas
Laboratório de Bioinformática
--
you seem to think that 'close enough' is close enough...
please learn to be 'literal' around programming.
merlyn - on irc.freenode.net#perl

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] assigning vars to $c-stash

2007-03-12 Thread Robert 'phaylon' Sedlacek

Eden Cardim wrote:


$c-stash( $hash );

is a little bit faster...


Correct.

--
# Robert 'phaylon' Sedlacek
# Perl 5/Catalyst Developer in Hamburg, Germany
{ EMail = ' [EMAIL PROTECTED] ', Web = ' http://474.at ' }

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] assigning vars to $c-stash

2007-03-12 Thread Octavian Rasnita

Thank you all for your solutions. I think this is the most simple.

Octavian

- Original Message - 
From: Eden Cardim [EMAIL PROTECTED]

To: The elegant MVC web framework catalyst@lists.rawmode.org
Sent: Monday, March 12, 2007 2:39 PM
Subject: Re: [Catalyst] assigning vars to $c-stash


On 3/12/07, Robert 'phaylon' Sedlacek [EMAIL PROTECTED] wrote:


   $c-stash( %$hash );


$c-stash( $hash );

is a little bit faster...

--
Eden Cardim
Instituto Baiano de Biotecnologia
Núcleo de Biologia Computacional e Gestão de Informações Biotecnológicas
Laboratório de Bioinformática
--
you seem to think that 'close enough' is close enough...
please learn to be 'literal' around programming.
merlyn - on irc.freenode.net#perl

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/ 



___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Detecting if a user aborted a (long) download

2007-03-12 Thread Wade . Stuart





 There are various compromises that you can make instead, including
 checking to
 see if the whole file at least made it out of your catalyst app (by
having
 your filehandle monitor that for you).  You can also give the user a good

 amount of time to download the file as many times as he likes (bandwidth
is
 cheap), or you can have customer support allow the user to re-download if
he
 complains (Apple does this).

 You are free to ignore all of the above advice.  It isn't my problem.


I agree with the above advice,  you may also note that if you are charging
for the downloads there may be legal/accounting reasons for this method
(that almost all electronic delivery systems use).  Technically, if you
deliver only over the internet you need to have a certain level of backup
to prove that the product was delivered or that the client had the ability
to receive the product (and request it again if she states that she was
unable to receive it) in many countries to be able to show revenue on your
books.  It may be worth your while to have both an accountant that
specializes in Internet delivery/booking and a lawyer give you some
guidance about what is required in your area to cover your bases.

-Wade



___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Performance

2007-03-12 Thread Jason Kohles

On Mar 9, 2007, at 10:04 AM, Robert 'phaylon' Sedlacek wrote:


Christopher H. Laco wrote:


Sure, it they're that different. The goal still stands, don't use
uri_for everywhere. Only use it when you really need it.


Jep. But this is not getting easier if you start to have captures  
in your chains. I'm still having high hopes to build something fast 
(er) with URI::Template.


I actually built something to do this just this weekend, because I  
had some big tables that were calling uri_for more than once for  
every row of the table.  I ended up doing something like this...


In the controller...

$c-stash-{ 'uri_templates' }-{ 'id' } = $c-req-uri_with 
( { object_id = '[*id*]' } )-as_string;


In the template

[% WHILE ( row = resultset.next ) %]
[% FOR col IN columns %]
[% IF uri_templates.$col %]
[% action_link( uri_templates.$col, row ) %]
[% ELSE %]
[% row.$col %]
[% END %]
[% END %]
[% END %]

Elsewhere...

sub action_link {
my ( $template, $object ) = @_;

while ( $template =~ /\[\*(\w+)\*\]/ ) {
my $i = $1;
my $rep = $object-$i();
$template =~ s/\[\*$i\*\]/$rep/g;
}
return $template;
}

I actually looked at URI::Template, and the one major issue I had  
with it was the choice of { and } as the template indicator  
characters, you can't do $c-req-uri_with( { foo = '{bar}' } ),  
since URI will escape the { and }, and your template will end up  
saying %7Bbar%7D instead of {bar}.


--
Jason Kohles
[EMAIL PROTECTED]
http://www.jasonkohles.com/
A witty saying proves nothing.  -- Voltaire


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Detecting if a user aborted a (long) download

2007-03-12 Thread Jeff Chimene

Jonathan Rockway wrote:

On Sunday 11 March 2007 21:18, Jeff Chimene wrote:
  

Jonathan Rockway wrote:


On Sunday 11 March 2007 20:59, Jeff Chimene wrote:
  

How does that differ from something that compares bytes sent to bytes
received? Assuming that the OP defines success when bytes received =
bytes sent


How do you determine how many bytes were received and successfully
written to disk?
  

There's also this:


http://ajaxpatterns.org/Progress_Indicator#What_sort_of_progress_indicato
r_will_you_use.3F
  


I think this thread has wandered a bit off topic.

That's hardly for you to decide, now is it?
  We are talking about how to 
ensure that a user has reliably downloaded and is able to access (from his 
own machine) an mp3 file.  
No, you are. The original question was I need to figure out if a user 
aborted a longish download.
The answer is that you can't do that without 
asking the user :)
  

To that question, you are correct. But, that's not the question.
There are various compromises that you can make instead, including checking to 
see if the whole file at least made it out of your catalyst app (by having 
your filehandle monitor that for you).  You can also give the user a good 
amount of time to download the file as many times as he likes (bandwidth is 
cheap), or you can have customer support allow the user to re-download if he 
complains (Apple does this).


You are free to ignore all of the above advice.  It isn't my problem.
  

Then why bother to reply?

Since we haven't heard from the OP. I have two questions:
o Did you investigate sendfile?
o Have you considered implementing a download progress indicator? One of 
the reasons users give up on downloads is that they don't know what's 
happening.



___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Detecting if a user aborted a (long) download

2007-03-12 Thread Wade . Stuart




 Since we haven't heard from the OP. I have two questions:
 o Did you investigate sendfile?

Sendfile() buys you nothing relevant to the OP's question.

 o Have you considered implementing a download progress indicator? One of
 the reasons users give up on downloads is that they don't know what's
 happening.

What browser are you using that does not:

1, have its own download session manager + progress display
2, where download app continues download even if you leave the page/site
that started it
3, and the browser tells you hey numbnuts, you are still downloading are
you sure you want to close? when you try to close your browser before the
download is complete.
4, where a separate download progress bar that is non standard would be
anything but confusing to a user?

The bottom line is, downloads break sometimes for many reasons.  Your app
(being on the server) will never be able to know if the download completes
or not unless you control the download end-to-end (such as writing and
distributing your own download manager).  A silly progress bar embedded in
your webapp does not get you past this problem.  A simple, smart and quite
frankly the industry standard solution is to allow the user to try again on
failure.






___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Detecting if a user aborted a (long) download

2007-03-12 Thread Dave Rolsky

On Mon, 12 Mar 2007, [EMAIL PROTECTED] wrote:


2, where download app continues download even if you leave the page/site
that started it


This is normal behavior. In Firefox, at least, once you start downloading 
the file, that's a separate request, unrelated to the page where I started 
the download. IIRC, IE has the same behavior.



-dave

/*===
VegGuide.Orgwww.BookIRead.com
Your guide to all that's veg.   My book blog
===*/

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Detecting if a user aborted a (long) download

2007-03-12 Thread Jay K

Hi Thomas,

Check out the code associated with the 2006 advent calendar entry
entitled 'streaming mp3s with Catalyst'

http://www.catalystframework.org/calendar/2006/15

It's a little more involved, in that it handles 'range' requests -
but the main portion of the mp3 sending should work for you, you'd
just have to add a byte counter and compare when the writing is
finished if all the data was sent or not.

The code you are interested in is lib/Streaming.pm - 'sub mp3 : Local'

That should get you most of what you need with some well chosen hackery.

As an aside - I don't know what you are doing with this - but in
terms of charging based on whether the file was downloaded in it's
entirety - with mp3s you can drop off the end usually without it
affecting playback much, if at all.

In other words - expect that people will figure out the billing
method and stop the download just a few bytes shy of the end of the
file to avoid paying.  (I've seen automated bookmarklet things that
do just that)  Just something to be aware of.

Jay


On Mar 11, 2007, at 9:26 AM, Thomas Klausner wrote:


Hi!

I need to figure out if a user aborted a longish download.  (some
background:
Users can download a limited amount of mp3s. If the download
doens't work for
some reason, they must not be charged)

In our old plain mod_perl 1.x handlers, I had something like:

$r-send_fd($fh);

if ($r-connection-aborted) {
# do stuff if user aborted download
}

Now, using Catalyst (on mod_perl 2.x), I'm doing this to send the
file:

$c-res-body( $fh );

But how do I figure out if the download was successfull? I didn't
find anything in the docs (but a RTFM-answer is appreciated, if I
missed the right piece of codocumentation).

Thanks!

--
#!/usr/bin/perl   http://domm.zsi.at
for(ref bless{},just'another'perl'hacker){s-:+-$-gprint$_.$/}

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/
catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


---
May we not return to those scoundrels of old, the illustrious
founders of superstition and fanaticism, who first took the knife
from the altar to make victims of those who refused to be their
disciples. - Voltaire



___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Detecting if a user aborted a (long) download

2007-03-12 Thread Thomas Klausner
Hi!

On Mon, Mar 12, 2007 at 01:21:45PM -0500, [EMAIL PROTECTED] wrote:

 your webapp does not get you past this problem.  A simple, smart and quite
 frankly the industry standard solution is to allow the user to try again on
 failure.

So I need to figure out if there was I failure. Which I did (in modperl 
1.x) using $r-connection-aborted.

I'm still not sure if sendfile() does the same, but it seems to do.
Or I can use $c-write, as in the Streaming.pm example suggested by Jay.



-- 
#!/usr/bin/perl   http://domm.zsi.at
for(ref bless{},just'another'perl'hacker){s-:+-$-gprint$_.$/}

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Detecting if a user aborted a (long) download

2007-03-12 Thread Wade . Stuart






 [EMAIL PROTECTED] wrote:
 
 
 
  Since we haven't heard from the OP. I have two questions:
  o Did you investigate sendfile?
 
 
  Sendfile() buys you nothing relevant to the OP's question.
 
 Really? The OP was merely detecting whether or not the session aborted,
 not whether or not the file successfully downloaded. Apparently
 sendfile() can return an error condition related to the OP's original
 design.

The point is it does not.  Welcome to the Internet where AOL's (google,
netspeed, isp X with SpeedupPro tech, or that silly corporate office) proxy
server/firewall/virus proxy has just soaked up the full download (no
sendfile or io dispatcher error) and the client only got half.  The OP's
assumption and initial implementation is obviously broke.  Handing him a
Jack to fix his airplane wing he is describing as a flat tire is a
disservice.



 
  o Have you considered implementing a download progress indicator? One
of
  the reasons users give up on downloads is that they don't know what's
  happening.
 
 
  What browser are you using that does not:
 
  1, have its own download session manager + progress display
  2, where download app continues download even if you leave the
page/site
  that started it
  3, and the browser tells you hey numbnuts, you are still downloading
are
  you sure you want to close? when you try to close your browser before
the
  download is complete.
  4, where a separate download progress bar that is non standard would be
  anything but confusing to a user?
 
  The bottom line is, downloads break sometimes for many reasons.  Your
app
  (being on the server) will never be able to know if the download
completes
  or not unless you control the download end-to-end (such as writing and
  distributing your own download manager).  A silly progress bar embedded
in
  your webapp does not get you past this problem.  A simple, smart and
quite
  frankly the industry standard solution is to allow the user to try
again on
  failure.
 
 It's not clear to me that the OP is using a browser, vs. some custom
 application that relies on HTTP protocol. Since the OP hasn't chimed in
 on this thread, I'm done answering these questions.

We were told enough information to know that the implementation was broken
and we are offering valid (unbroken or not-so-broke) alternatives.  And as
another poster said:  The advice is free -- take it or leave it.



___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Detecting if a user aborted a (long) download

2007-03-12 Thread Carl Johnstone


Here's a worst-case scenario you send it to IE and somewhere along the 
line it picks up a Vary header.


IE won't store anything in it's cache with a Vary header - not even 
downloaded files. So it downloads the file then deletes it.


You can't save it elsewhere or retrieve it!

http://support.microsoft.com/?kbid=824847

(By the way it exhibits the same behaviour if you send proper no-cache 
headers.)


So as far as the server is concerned, your logs are concerned, and 
anything else you are concerned that file has been delivered to the 
client successfully. As far as the user is concerned you may as well not 
have bothered as the browser's eaten the download.


Carl


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/