You could build such a corral, but good luck keeping the birds inside. Whether the rules you set on your published open code are copyright, copyleft, or one of the myriad other open-source licenses now governing development efforts, good luck keeping the code inside. The spirit of open source is the sharing of information and the belief that people working together solve problems better and more efficiently than people working in isolation. Experience suggests that the noble beliefs embodied in the open-source movement are, in fact, true. This really happens.
Software is better when lots of people work to create it, then debug it, and use it.
But while the open-source movement may be driven by a shared belief about the benefit of working in the open, those participating in it don't publish their work in the public domain. In the public domain, information is free to be used by anyone, for any purpose, commercial or noncommercial, sometimes even without attribution. That's not how open source works. Open source takes all the component parts of software and lays them bare for anyone to see, revise, or build upon. But there are strings attached.